节点MySQL查询语法错误

时间:2014-03-16 21:39:22

标签: javascript mysql node.js node-mysql

我试图查询我的数据库,但收到错误:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual th
at corresponds to your MySQL server version for the right syntax to use near 'gr
oup = 'new_fire', date = '2014-03-16', price = '', customer = '', seller = 'no'
at line 1

但我似乎无法找到语法错​​误。我认为这与我将查询与nodeMySQL模块放在一起的方式有关。

这是我的相关节点查询代码段:

var salesData = [category, group, date, price, customer, name, commission];

...

connection.query(
'INSERT INTO `officeball`.`sales_entries` SET category = ?, group = ?, date = ?, price = ?, customer = ?, seller = ?, commission = ?',
salesData
)

最后由phpmyadmin生成的查询,我的意思是执行:

INSERT INTO `officeball`.`sales_entries` (`sale_id`, `category`, `group`, `date`, `price`, `customer`, `seller`, `accepted`, `commission`, `commission_status`) VALUES ('', 'fire', 'new_fire', '2014-03-16', '123', 'joey bob', 'node user', '', '34', '')

我将acceptedcommission_status留在节点查询中,它们可以保持空白。

此查询中出现错误?

1 个答案:

答案 0 :(得分:4)

group是mysql保留的关键字,用这样的反引号包围它:

   INSERT INTO `officeball`.`sales_entries` SET category = ?, `group` = ? .....

以下是文档中的reserved keywords