[英]Insterting array as parameter to query in node.js mySQL
我嘗試搜索此內容,但大多數結果將我帶到了不需要atm的Node.js批量插入中。 據我了解,批量插入意味着插入多行,而我不需要。
我正在嘗試使用對象數組作為查詢的參數:
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
我應該怎么做?
如果您想將其保存為row
請不要使用[]
換row
嘗試這個
connection.query("INSERT INTO `domicilio` SET ?", new_Domicilio, function(err, results) {
if(err) {
console.log(err);
return;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.