【发布时间】:2017-01-30 02:19:49
【问题描述】:
我尝试搜索此内容,但大多数结果将我带到 Node.js 中的批量插入,而我不需要 atm。据我了解,批量插入意味着插入多行,我不需要。
我正在尝试使用对象数组作为查询的参数:
function saveDomicilio(id_establecimiento, token, order, total){
var order = [{"id":1,"quantity":2},{"id":"3","quantity":"4"}];
console.log("Order" + order); // logs correctly my order
var new_Domicilio = {
id_establecimiento: id_establecimiento,
id_usuario: token,
orden: order,
total : total
};
pool.getConnection(function(err, connection) {
if(err) {
console.log(err);
return;
}
// make the query
connection.query("INSERT INTO domicilio SET ?", [new_Domicilio], function(err, results) {
if(err) {
console.log(err);
return;
}
console.log("New domicilio created");
return;
}); // query
}); // pool
};
使用数组似乎有问题我收到错误:
{ [错误:ER_PARSE_ERROR:您的 SQL 语法有错误;查看与您的 MySQL 服务器版本相对应的手册,了解在 ''{\"id\":1,\"cantidad\":2}',
附近使用的正确语法total= 300
我该怎么做?
【问题讨论】:
-
你不打电话给
2 rows,multiple rows吗? -
不,我不这么认为?我只想将 new_Domicilio 插入一行
-
数组中有 2 个对象,表示 2 行。你怎么能把它保存到一行?你的表结构是什么?
-
order是text类型。我正在尝试将那个数组保存在那里。我认为不太重要的其他参数是:id_establecimiento:int,id_usuario:int,total:int
标签: javascript mysql arrays node.js