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
代码:(
$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)
任何帮助将不胜感激!
谢谢!
I'm trying to get the code below to work.....
The error:
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
The code:
$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();}
}
(Using PHP PDO and MySQL)
Any help would be appreciated!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您正在尝试准备一条语句,但您正在执行它(通过
query()
)而不是准备它。将
->query(...);
更改为->prepare(...);
并保留其余部分不变...PDO::Prepare()
The problem is that you're trying to prepare a statement, yet you're executing it (via
query()
) instead of preparing it.Change
->query(...);
to->prepare(...);
and leave the rest as is...PDO::Prepare()