我在这里做错了什么?我想也许 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);
# }
#}