phpでpdoを使いテーブルを作成しているのですが、投稿時間の部分がうまくいきません。
php
1<?php 2 3header("Content-Type: text/html; charset=UTF-8"); 4 $pdo = new PDO($dsn,$user,$password); 5 $sql = "CREATE TABLE keijiban" 6 ."(" 7 ."id INT," 8 ."name char(32)," 9 ."comment TEXT," 10 ."created_on DATETIME" 11 .");"; 12 $stmt = $pdo->query($sql); 13 14 $sql = "SHOW TABLES"; 15 $result = $pdo->query($sql); 16 foreach($result as $row){ 17 echo $row[0]; 18 echo "<br>"; 19 } 20 echo "<hr>"; 21 22 $sql = "SHOW CREATE TABLE keijiban"; 23 $result = $pdo->query($sql); 24 foreach((array)$result as $row){ 25 print_r($row); 26 } 27 echo "<hr>"; 28 29 30 $DATETIME = new DateTime(); 31 $DATETIME = $DATETIME->format('Y-m-d H:i:s'); 32 $sql = $pdo->prepare("INSERT INTO keijiban(id,name,comment,created_on) VALUES ('1',:name,:comment,:created_on)"); 33 $sql->bindParam(":name",$name,PDO::PARAM_STR); 34 $sql->bindParam(":comment",$comment,PDO::PARAM_STR); 35 $sql->bindValue(":created_on",$DATETIME,PDO::PARAM_STR); 36 $name = "namae"; 37 $comment = "aaa"; 38 $sql -> execute(); 39 40 $sql = "SELECT*FROM keijiban"; 41 $results = $pdo->query($sql); 42 foreach((array)$results as $row){ 43 echo $row['id'].","; 44 echo $row['name'].","; 45 echo $row['comment'].","; 46 echo $row['created_on'].'<br>'; 47 } 48 49 50 51 52?> 53 54<!DOCTYPE html> 55<html lang="ja"> 56<head> 57 <meta charset = "UTF-8"> 58 <title> 59 </title> 60</head> 61<body> 62</body> 63</html> 64 65
DATATIMEの中に日付を代入し、それを表示させるようにしたいのですがうまくいきません。これをブラウザ上でひょうじさせたら何もうつらなくなってしまいました。どのように修正すればいいでしょうか?ご教授いただけるとありがたいです。
回答2件
あなたの回答
tips
プレビュー