简体   繁体   English

MySQL插入具有多个字段和where子句

[英]MySQL insert with multiple fields and where clause

I'm trying to construct a query for a cron that will run. 我正在尝试为将要运行的cron构建查询。

mysql_query("UPDATE `stocks` SET price='$pricez', open='$openz', high='$highz', low='$lowz', change='$changez', time='$times', percent='$percentz' WHERE symbol = '$symbolz' "); 

The error I get is 我得到的错误是

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

Scavenged SOF and have yet to find a solution. 清除了SOF,尚未找到解决方案。

Looks like you are using some reserved words for column names: Change and Time You can escape these with backticks (`), or choose new coumn names 好像您在列名称中使用了一些保留字:更改和时间您可以使用反引号(`)进行转义,或者选择新的列名

UPDATE `stocks` 
SET     `price`='$pricez', 
        `open`='$openz', 
        `high`='$highz', 
        `low`='$lowz', 
        `change`='$changez', 
        `time`='$times', 
        `percent`='$percentz' 
WHERE symbol = '$symbolz' 

Reserved words just bit you: Change is a reserved word thus needs to be escaped: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html 保留字只会对您造成影响:更改是保留字,因此需要转义: 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' ");

So what is a reserved word? 那么什么是保留字?

They are words the engine uses to interpert specific requested commands. 它们是引擎用来打断特定请求命令的词。 When these words are used as identifiers for tables or columns they must be treated in a specific manner usually escaping the words for the RDBMS involved. 当将这些单词用作表或列的标识符时,必须以特定的方式对待它们,通常会将所涉及的RDBMS的单词转义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM