[英]Node.js Api, can't delete from database
I'm working on an Angular
project so I wanted to make a simple Rest API
to handle a MySql database
, that's why I made one in Node.js but when I tried to delete an item with id = 3
, I'm only getting an error看起来像这样:
errno: 1064,
sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1",
sqlState: '42000',
index: 0,
sql: 'DELETE FROM recipies WHERE id = ?'
所以我想寻求帮助。 我在想我收到了这个错误,因为这几行有一些逻辑问题:
Recipe.remove = (id, result) => {
sql.query("DELETE FROM recipies WHERE id = ?", id, (err,res) => {
if (err) {
console.log("error", err);
result(null, err);
return;
}
if (res.affectedRows == 0) {
// not found recipe with the id
result({ kind: "not_found" }, null);
return;
}
console.log("deleted customer with id: ", id);
result(null, res);
});
};
错误信息一直在告诉你!
在 NodeJS 中,要替换查询 arguments,您可以将它们列在一个数组中作为查询的第二个参数。
sql.query("DELETE FROM recipies WHERE id = ?", [ id ], (err,res) => {...
出现了一个错字: recipeID ,应该是recipeId
但是mods编辑了我的帖子,所以你可能永远不知道在哪里......
记住,总是看看你是否有错别字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.