我正在尝试为将要运行的 cron 构建一个查询。
mysql_query("UPDATE `stocks` SET price='$pricez', open='$openz', high='$highz', low='$lowz', change='$changez', time='$times', percent='$percentz' WHERE symbol = '$symbolz' ");
我得到的错误是
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 'change='-0.10', time='1406050151', percent='-0.35%' WHERE symbol = 'ALMB.CO'' at line 1
已清除 SOF,但尚未找到解决方案。
最佳答案
保留字只会咬你: Change 是一个保留字,因此需要转义:http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
mysql_query("UPDATE `stocks` SET price='$pricez', open='$openz', high='$highz',
low='$lowz', `change`='$changez', time='$times', percent='$percentz' WHERE symbol = '$symbolz' ");
那么什么是保留字呢?
它们是引擎用来解释特定请求命令的词。当这些词用作表或列的标识符时,必须以特定方式处理它们,通常对涉及的 RDBMS 的词进行转义。
关于php - MySQL 插入多个字段和 where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24894009/