【发布时间】:2018-10-09 18:48:12
【问题描述】:
我想更新几个表如下:
for ($i=0; $i <count($tablesnames); $i++) {
$update3=$pdo->prepare('UPDATE :surveytable SET `postrecords`=:newrecord WHERE `id`=:id');
//var_dump()here
$update3->bindValue(':surveytable', $tablesnames[$i],PDO::PARAM_STR);
$update3->bindValue(':newrecord',$newrecord,PDO::PARAM_STR);
$update3->bindValue(':id',$id,PDO::PARAM_INT);
$update3->execute();
}
检查var_dump结果,$tablesnames[$i]和$newrecord是string,$id是int,$update3是false。
似乎一切正常,但失败了,
警告:PDO::prepare(): SQLSTATE[42000]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以了解在 '? 附近使用的正确语法。设置
postrecords=?在哪里id=?
有什么问题?
【问题讨论】:
标签: pdo