为什么mysql转义符破坏了整个查询?

时间:2019-05-08 21:34:54

标签: mysql sql node.js syntax-error

我一直在尝试在此查询中查找问题,但似乎找不到,这使我发疯。这是我的代码:

sql.query("INSERT INTO coinflips (host,host_side,items,join,expires,value,secret,hash,winningPercentage) VALUES (?,?,?,?,?,?,?,?,?)",[" "," "," "," "," ",0," "," ",0.5],(err)=>{
        if(err) return console.log(err);
});

但是,出现以下错误:

'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 \'join,expires,value,secret,hash,winningPercentage) VALUES (\' \',\' \',\' \',\' \',\' \',0,\' at line 1'

这是数据库:

https://ibb.co/LdywXQN

我从来没有遇到过转义查询的问题,但是突然这一次停止了工作,我不明白为什么。

1 个答案:

答案 0 :(得分:2)

join是保留字,您必须使用反引号将其转义:

sql.query("INSERT INTO coinflips (host,host_side,items,`join`,expires,value,secret,hash,winningPercentage) VALUES (?,?,?,?,?,?,?,?,?)",[" "," "," "," "," ",0," "," ",0.5],(err)=>{
    // Here -------------------------------------------^----^
    if(err) return console.log(err);
});