我有一个像这样的MySQL表:
下面是我试图将数据插入mysql表的代码:
var data = {
id : 1,
custname : input.custname,
custemail : input.custemail,
ordertype : input.ordertype,
noorder : input.noorder,
orderdate : input.orderdate
};
var query = connection.query('INSERT INTO order SET ?', data, function(err,rows) {
if (err)
console.log("Error inserting : %s ",err );
res.render('createorder', {title :"Order Created Successfully"});
});
但是给了我以下错误:
INSERT INTO order SET `id` = 1, `custname` = 's', `custemail` = 's@gmail.com', `ordertype` = 'Chalbhaja', `noorder` = 2, `orderdate` = '2015-07-24T16:07:58.684Z'
Error inserting : 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 'order SET `id` = 1, `custname` = 's', `custemail` = 's@gmail.com', `ordertype` =' at line 1
答案 0 :(得分:2)
order
字是MySQL中的关键字。但是可以有一个名为order
的表。您只需在查询中将其转义,例如:
var query = connection.query('INSERT INTO `order` SET ?', data, function(err,rows) {
if (err)
console.log("Error inserting : %s ",err );
res.render('createorder', {title :"Order Created Successfully"});
});