質問編集履歴
1
追記部分コード
title
CHANGED
File without changes
|
body
CHANGED
@@ -199,4 +199,156 @@
|
|
199
199
|
フォトで開こうとすると
|
200
200
|
このファイルはサポートされていない形式のようです。となります。
|
201
201
|
|
202
|
-
サーバにアップロードする前には、開けるので 自分の書いたどこかのプログラムがおかしいとは思うのですが、 原因が特定できなかったのでアドバイス頂けると助かります。
|
202
|
+
サーバにアップロードする前には、開けるので 自分の書いたどこかのプログラムがおかしいとは思うのですが、 原因が特定できなかったのでアドバイス頂けると助かります。
|
203
|
+
|
204
|
+
--追記--
|
205
|
+
```php
|
206
|
+
<?php
|
207
|
+
namespace DBIO;
|
208
|
+
|
209
|
+
use PDO;
|
210
|
+
use PDOException;
|
211
|
+
|
212
|
+
class MyPDO{
|
213
|
+
|
214
|
+
private $dsn;
|
215
|
+
private $user;
|
216
|
+
private $pass;
|
217
|
+
private $pdo;
|
218
|
+
|
219
|
+
function __construct(){
|
220
|
+
|
221
|
+
$this->dsn = "mysql:dbname=test;host=localhost;charset=utf8mb4";
|
222
|
+
$this->user = "root";
|
223
|
+
$this->pass = "";
|
224
|
+
$this->connect();
|
225
|
+
}
|
226
|
+
|
227
|
+
function connect(){
|
228
|
+
|
229
|
+
$this->pdo = new PDO($this->dsn, $this->user, $this->pass, array(
|
230
|
+
PDO::ATTR_PERSISTENT => true
|
231
|
+
));
|
232
|
+
}
|
233
|
+
|
234
|
+
function close(){
|
235
|
+
|
236
|
+
$this->pdo = null;
|
237
|
+
}
|
238
|
+
|
239
|
+
function getAll(){
|
240
|
+
|
241
|
+
$sql = "SELECT * FROM images";
|
242
|
+
$this->connect();
|
243
|
+
$tmp = $this->pdo->query($sql);
|
244
|
+
|
245
|
+
// 全部の行を配列して返す
|
246
|
+
$result = $tmp->fetchAll();
|
247
|
+
$this->close();
|
248
|
+
|
249
|
+
return $result;
|
250
|
+
}
|
251
|
+
|
252
|
+
function getInfo($id){
|
253
|
+
|
254
|
+
$sql = "SELECT * FROM images WHERE id=?";
|
255
|
+
$this->connect();
|
256
|
+
$stmt = $this->pdo->prepare($sql);
|
257
|
+
$stmt->bindParam(1, $id);
|
258
|
+
|
259
|
+
// 戻り値 成功でtrueが返ってくる
|
260
|
+
$stmt->execute();
|
261
|
+
$result = $stmt->fetchAll();
|
262
|
+
|
263
|
+
$this->close();
|
264
|
+
|
265
|
+
return $result;
|
266
|
+
}
|
267
|
+
|
268
|
+
// データベースに画像情報一行分のレコードを追加
|
269
|
+
function insertImgInfo_recode($title, $info, $photographer, $filePath){
|
270
|
+
try {
|
271
|
+
|
272
|
+
// SQLの実行結果の判断
|
273
|
+
// $result = false;
|
274
|
+
|
275
|
+
$sql = "INSERT INTO images(TITLE, INFO, PHOTOGRAPHER, PATH, DATE) VALUES(?,?,?,?,?)";
|
276
|
+
$date = date("Y/m/d G:i:s");
|
277
|
+
$this->connect();
|
278
|
+
$stmt = $this->pdo->prepare($sql);
|
279
|
+
$stmt->bindParam(1, $title);
|
280
|
+
$stmt->bindParam(2, $info);
|
281
|
+
$stmt->bindParam(3, $photographer);
|
282
|
+
$stmt->bindParam(4, $filePath);
|
283
|
+
$stmt->bindParam(5, $date);
|
284
|
+
// 実行結果
|
285
|
+
$result = $stmt->execute();
|
286
|
+
} catch (PDOException $e) {
|
287
|
+
print('PDOException:' . $e->getMessage());
|
288
|
+
} finally{
|
289
|
+
|
290
|
+
$this->close();
|
291
|
+
}
|
292
|
+
//実行結果が成功か失敗かを返す: true/flse
|
293
|
+
return $result;
|
294
|
+
}
|
295
|
+
|
296
|
+
|
297
|
+
//データベースimagesテーブルの全てのデータ取得
|
298
|
+
|
299
|
+
function getRecodeAll(){
|
300
|
+
|
301
|
+
$sql = "SELECT * FROM images";
|
302
|
+
$this->connect();
|
303
|
+
$stmt = $this->pdo->prepare($sql);
|
304
|
+
|
305
|
+
$stmt->execute();
|
306
|
+
$recode = $stmt->fetchAll();
|
307
|
+
$this->close();
|
308
|
+
|
309
|
+
//テーブルの全てのデータを返す
|
310
|
+
return $recode;
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
//idで一行分のレコード取得
|
315
|
+
function getRecode($id){
|
316
|
+
|
317
|
+
$sql = "SELECT * FROM images WHERE ID = ?";
|
318
|
+
$this->connect();
|
319
|
+
$stmt = $this->pdo->prepare($sql);
|
320
|
+
$stmt->bindParam(1, $id);
|
321
|
+
$stmt->execute();
|
322
|
+
$recode = $stmt->fetchAll();
|
323
|
+
$this->close();
|
324
|
+
|
325
|
+
//一行分のデータを返す
|
326
|
+
return $recode;
|
327
|
+
}
|
328
|
+
|
329
|
+
|
330
|
+
function updateRecode($id,$title,$image_info,$photographer){
|
331
|
+
|
332
|
+
|
333
|
+
$sql = "UPDATE images SET TITLE=?, INFO=?, PHOTOGRAPHER=?, DATE=? where ID = ?";
|
334
|
+
|
335
|
+
$date = date("Y/m/d G:i:s");
|
336
|
+
$this->connect();
|
337
|
+
$stmt = $this->pdo->prepare($sql);
|
338
|
+
|
339
|
+
$stmt->bindParam(1, $title);
|
340
|
+
$stmt->bindParam(2, $image_info);
|
341
|
+
$stmt->bindParam(3, $photographer);
|
342
|
+
$stmt->bindParam(4, $date);
|
343
|
+
$stmt->bindParam(5, $id);
|
344
|
+
$result = $stmt->execute();
|
345
|
+
|
346
|
+
$this->close();
|
347
|
+
|
348
|
+
//更新結果が成功ならtrue/失敗ならfalse
|
349
|
+
return $result;
|
350
|
+
}
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
```
|