ここで何が間違っていますか?exec の変数に問題があるのではないかと思いましたが、別の場所で動作する類似コマンドがあります。コメント部分は影響を受けた行として int(1) を返し、このコードは次のエラーを返します。あなたのアドバイスに感謝します。私はただ学んでいます。
"object(PDO)#2 (0) { } Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'try, Wed, 06 Mar 2013 13:25:09 +0200)' at line 1 ) "
コード:
<?php
class gbMsg {
private $_db;
private $dbc;
function __construct(){
$this->dbc = parse_ini_file($_SERVER["DOCUMENT_ROOT"]."/lock/conect.ini");
try{
$this->_db = new PDO($this->dbc["conn"], $this->dbc["user"], $this->dbc["pass"]);
}catch(PDOException $e){
echo $e->getMessage();
}
}
function addPost($name, $msg){
echo var_dump($this->_db);
$d = date("r");
$stmt = $this->_db->exec("INSERT INTO gPosts (name, message, date) VALUES ($name,$msg, now())")
or die(print_r($this->_db->errorInfo(), true));
echo var_dump($stmt);
}
}
# function addPost(){
# echo var_dump($this->_db);
# $stmt = $this->_db->exec("INSERT INTO gPosts (name, message, date) VALUES ('Kirill','sec', now())");
# echo var_dump($stmt);
# }
#}