2016-09-14 107 views
1

这是代码的一部分,我用节点JS插入Mysql的不工作

var insertedData = { 
     name: 'testname', 
     score: '1337' 
    }; 
connect.query('INSERT INTO table SET ?', insertedData, function(error, result){ 

,这是我得到

{ [Error: ER_PARSE_ERROR: 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 'table SET name = 'Hek', score = '12'' at line 1]code: 'ER_PARSE_ERROR', errno: 1064, sqlState: '42000',index: 0 }

回答

0

table是在MySQL中保留字的错误。我建议将你的表重命名为别的东西。如果这绝对不是你的可能性,你可以用反引号来逃避它:

connect.query('INSERT INTO `table` SET ?', insertedData, function(error, result){ 
+0

好的发现,但它实际上是一个插入语句。仍然不正确 – Shaharyar

+0

@Shaharyar INSERT ... SET是MySQL中的有效语法。这不是标准的ANSI,但它对于MySQL来说非常好。 – Mureinik

+1

非常感谢,它的工作 –