我在将参数发送到我的方法时遇到了一个我不明白的错误,我认为我的查询错了,但我手动完成了,而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);
});
});
};
我得到的错误是:
抛出错误; //重新抛出非MySQL错误 ^TypeError:this._callback.apply不是函数
答案 0 :(得分:1)
查询参数应该在数组中传递:
connection.query("DELETE FROM favorites WHERE id_user = ? AND id_restaurant = ?", [ id_user, id_restaurant ], function(err, results) {
...
});