Php PDO插入错误
我正在尝试让下面的代码正常工作 错误:Php PDO插入错误,php,mysql,pdo,Php,Mysql,Pdo,我正在尝试让下面的代码正常工作 错误: ERRORSQLSTATE[42000]: Syntax error or access violation: 1064 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 '?, ?, ?, ?)' at line 1 守则: $da
ERRORSQLSTATE[42000]: Syntax error or access violation: 1064
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 '?, ?, ?, ?)' at line 1
守则:
$data=array($idApplications,$author,$addedOn,$note);
try {
$STH = $this->DBH->query('
INSERT INTO '.$table.' (idApplications,Author,NoteAddedOn,Note)
VALUES (?, ?, ?, ?)
');
$STH->execute($data);
}
catch(PDOException $e) {echo $e->getMessage();}
}
(使用PHP PDO和MySQL)
任何帮助都将不胜感激
谢谢 问题在于,您试图准备一条语句,但却在执行它(通过
query()
),而不是准备它
更改->查询(…)代码>到->准备(…)代码>并保持其余部分不变
您可能希望在变量中创建查询字符串,然后将其传递给query()方法,因此它将是$query='INSERT-INTO….'$STH->execute($query);?这种方法有什么优点/缺点吗?啊!这就解决了问题。谢谢!:)(正如你所知道的,我还在学习PDO!)没问题。我们都会犯错误。我们唯一能做的就是向他们学习。。。