且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

警告:PDO :: prepare():SQLSTATE [42000]:语法错误或访问冲突:更新时为1064

更新时间:2022-01-18 21:23:48

(不幸的是),您不能在准备好的语句中为表名使用参数.您只能将它们用于数据文字.因此UPDATE :surveytable无效.

(Unfortunately) you can't use parameters for your tablename in your prepared statement. You can only use those for data literals. So UPDATE :surveytable is invalid.

按照手册:

参数标记只能代表完整的数据文字.两者都不 文字,关键字,也不是标识符或任何任意形式的一部分 可以使用参数来绑定查询部分.

Parameter markers can represent a complete data literal only. Neither part of literal, nor keyword, nor identifier, nor whatever arbitrary query part can be bound using parameters.

当您(完全!!!! )信任您的$tablesnames来源时,请使用

When you (completely!!!) trust your source of $tablesnames, use

'UPDATE `' . $tablesnames[i]` . '` SET `postrecords`=:newrecord WHERE `id`=:id'

代替