gpt4 book ai didi

javascript - 在node.js中从mySQL删除时出错

转载 作者:行者123 更新时间:2023-11-29 11:28:17 25 4
gpt4 key购买 nike

在将参数发送到我的方法时,我收到一个我不明白的错误,我认为我的查询是错误的,但我手动执行了它,并且 mySQL 做了它必须做的事情。所以问题出在我的代码中,但我似乎找不到哪里,提前谢谢。

exports.defav = function(id_user, id_restaurant, callback){

console.log(id_user + " " + id_restaurant); //Just making sure i'm reciving correclt
pool.getConnection(function(err, connection){
if(err){
console.log(err);
callback(true);
return;
}

connection.query("DELETE FROM favorites WHERE id_user = ? AND id_restaurant = ?", id_user, id_restaurant, function(err, results) {
console.log("SUCCESS: Removed from fav ");
connection.release();
if(err){
console.log(err);
callback(true);
return;
}

callback(results);
});
});
};

我收到的错误是:

throw err; // Rethrow non-MySQL errors ^

TypeError: this._callback.apply is not a function

最佳答案

查询参数应以数组形式传递:

connection.query("DELETE FROM favorites WHERE id_user = ? AND id_restaurant = ?", [ id_user, id_restaurant ], function(err, results) {
...
});

关于javascript - 在node.js中从mySQL删除时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37842737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com