2016-09-14 11 views
1

は、これは私がノードJS挿入MySQLのdoesntの仕事

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

ありがとう、それは働いた –

関連する問題