使用where子句的Insert语句无法在Node.js mysql上运行

问题描述:

代码:

function setvalue(val) {

        idoutput=val;
        base62val=Base.encode(idoutput);
        var baseinsert = {ShortUrlCode:base62val};
        console.log(idoutput);
        console.log(base62val);
        con.query('INSERT INTO URLTABLE set ?  where ID = ?',[baseinsert,idoutput],function(err){
        if(err) console.log(err);
        })
        console.log("short inserted");
        con.end();
}

我收到错误:

{ [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 'where ID = 38' at line 1]
  code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlState: '42000',
  index: 0 }

'INSERT INTO URLTABLE set ?  where ID = ?'

您忘记提及要设置"的列名.

You forgot to mention column names that you want to "SET".

 'INSERT INTO URLTABLE SET column_name = ? (, column_name2 = ?,...) WHERE ID = ?'

是正确的语法

请注意,始终最好标准化" SQL查询,在这种情况下,最好将以下标准SQL语法用于INSERT(而不是使用特定的MySQL语法):

Note that it is always better to "standardize" your SQL queries, in which case you better use the standard SQL syntax below for an INSERT (instead of using your specific MySQL syntax):

插入URLTABLE(a,b,c)值(?,?,?)