質問編集履歴
1
追記部分コード
test
CHANGED
File without changes
|
test
CHANGED
@@ -401,3 +401,307 @@
|
|
401
401
|
|
402
402
|
|
403
403
|
サーバにアップロードする前には、開けるので 自分の書いたどこかのプログラムがおかしいとは思うのですが、 原因が特定できなかったのでアドバイス頂けると助かります。
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
--追記--
|
408
|
+
|
409
|
+
```php
|
410
|
+
|
411
|
+
<?php
|
412
|
+
|
413
|
+
namespace DBIO;
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
use PDO;
|
418
|
+
|
419
|
+
use PDOException;
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
class MyPDO{
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
private $dsn;
|
428
|
+
|
429
|
+
private $user;
|
430
|
+
|
431
|
+
private $pass;
|
432
|
+
|
433
|
+
private $pdo;
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
function __construct(){
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
$this->dsn = "mysql:dbname=test;host=localhost;charset=utf8mb4";
|
442
|
+
|
443
|
+
$this->user = "root";
|
444
|
+
|
445
|
+
$this->pass = "";
|
446
|
+
|
447
|
+
$this->connect();
|
448
|
+
|
449
|
+
}
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
function connect(){
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
$this->pdo = new PDO($this->dsn, $this->user, $this->pass, array(
|
458
|
+
|
459
|
+
PDO::ATTR_PERSISTENT => true
|
460
|
+
|
461
|
+
));
|
462
|
+
|
463
|
+
}
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
function close(){
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
$this->pdo = null;
|
472
|
+
|
473
|
+
}
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
function getAll(){
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
$sql = "SELECT * FROM images";
|
482
|
+
|
483
|
+
$this->connect();
|
484
|
+
|
485
|
+
$tmp = $this->pdo->query($sql);
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
// 全部の行を配列して返す
|
490
|
+
|
491
|
+
$result = $tmp->fetchAll();
|
492
|
+
|
493
|
+
$this->close();
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
return $result;
|
498
|
+
|
499
|
+
}
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
function getInfo($id){
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
$sql = "SELECT * FROM images WHERE id=?";
|
508
|
+
|
509
|
+
$this->connect();
|
510
|
+
|
511
|
+
$stmt = $this->pdo->prepare($sql);
|
512
|
+
|
513
|
+
$stmt->bindParam(1, $id);
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
// 戻り値 成功でtrueが返ってくる
|
518
|
+
|
519
|
+
$stmt->execute();
|
520
|
+
|
521
|
+
$result = $stmt->fetchAll();
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
$this->close();
|
526
|
+
|
527
|
+
|
528
|
+
|
529
|
+
return $result;
|
530
|
+
|
531
|
+
}
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
// データベースに画像情報一行分のレコードを追加
|
536
|
+
|
537
|
+
function insertImgInfo_recode($title, $info, $photographer, $filePath){
|
538
|
+
|
539
|
+
try {
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
// SQLの実行結果の判断
|
544
|
+
|
545
|
+
// $result = false;
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
$sql = "INSERT INTO images(TITLE, INFO, PHOTOGRAPHER, PATH, DATE) VALUES(?,?,?,?,?)";
|
550
|
+
|
551
|
+
$date = date("Y/m/d G:i:s");
|
552
|
+
|
553
|
+
$this->connect();
|
554
|
+
|
555
|
+
$stmt = $this->pdo->prepare($sql);
|
556
|
+
|
557
|
+
$stmt->bindParam(1, $title);
|
558
|
+
|
559
|
+
$stmt->bindParam(2, $info);
|
560
|
+
|
561
|
+
$stmt->bindParam(3, $photographer);
|
562
|
+
|
563
|
+
$stmt->bindParam(4, $filePath);
|
564
|
+
|
565
|
+
$stmt->bindParam(5, $date);
|
566
|
+
|
567
|
+
// 実行結果
|
568
|
+
|
569
|
+
$result = $stmt->execute();
|
570
|
+
|
571
|
+
} catch (PDOException $e) {
|
572
|
+
|
573
|
+
print('PDOException:' . $e->getMessage());
|
574
|
+
|
575
|
+
} finally{
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
$this->close();
|
580
|
+
|
581
|
+
}
|
582
|
+
|
583
|
+
//実行結果が成功か失敗かを返す: true/flse
|
584
|
+
|
585
|
+
return $result;
|
586
|
+
|
587
|
+
}
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
//データベースimagesテーブルの全てのデータ取得
|
594
|
+
|
595
|
+
|
596
|
+
|
597
|
+
function getRecodeAll(){
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
$sql = "SELECT * FROM images";
|
602
|
+
|
603
|
+
$this->connect();
|
604
|
+
|
605
|
+
$stmt = $this->pdo->prepare($sql);
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
$stmt->execute();
|
610
|
+
|
611
|
+
$recode = $stmt->fetchAll();
|
612
|
+
|
613
|
+
$this->close();
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
//テーブルの全てのデータを返す
|
618
|
+
|
619
|
+
return $recode;
|
620
|
+
|
621
|
+
}
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
//idで一行分のレコード取得
|
628
|
+
|
629
|
+
function getRecode($id){
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
$sql = "SELECT * FROM images WHERE ID = ?";
|
634
|
+
|
635
|
+
$this->connect();
|
636
|
+
|
637
|
+
$stmt = $this->pdo->prepare($sql);
|
638
|
+
|
639
|
+
$stmt->bindParam(1, $id);
|
640
|
+
|
641
|
+
$stmt->execute();
|
642
|
+
|
643
|
+
$recode = $stmt->fetchAll();
|
644
|
+
|
645
|
+
$this->close();
|
646
|
+
|
647
|
+
|
648
|
+
|
649
|
+
//一行分のデータを返す
|
650
|
+
|
651
|
+
return $recode;
|
652
|
+
|
653
|
+
}
|
654
|
+
|
655
|
+
|
656
|
+
|
657
|
+
|
658
|
+
|
659
|
+
function updateRecode($id,$title,$image_info,$photographer){
|
660
|
+
|
661
|
+
|
662
|
+
|
663
|
+
|
664
|
+
|
665
|
+
$sql = "UPDATE images SET TITLE=?, INFO=?, PHOTOGRAPHER=?, DATE=? where ID = ?";
|
666
|
+
|
667
|
+
|
668
|
+
|
669
|
+
$date = date("Y/m/d G:i:s");
|
670
|
+
|
671
|
+
$this->connect();
|
672
|
+
|
673
|
+
$stmt = $this->pdo->prepare($sql);
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
$stmt->bindParam(1, $title);
|
678
|
+
|
679
|
+
$stmt->bindParam(2, $image_info);
|
680
|
+
|
681
|
+
$stmt->bindParam(3, $photographer);
|
682
|
+
|
683
|
+
$stmt->bindParam(4, $date);
|
684
|
+
|
685
|
+
$stmt->bindParam(5, $id);
|
686
|
+
|
687
|
+
$result = $stmt->execute();
|
688
|
+
|
689
|
+
|
690
|
+
|
691
|
+
$this->close();
|
692
|
+
|
693
|
+
|
694
|
+
|
695
|
+
//更新結果が成功ならtrue/失敗ならfalse
|
696
|
+
|
697
|
+
return $result;
|
698
|
+
|
699
|
+
}
|
700
|
+
|
701
|
+
}
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
|
706
|
+
|
707
|
+
```
|