【发布时间】:2020-09-15 18:30:54
【问题描述】:
我一直在拼命想找出我所拥有的 mySQL 语法的问题。我收到了错误:
{"message":"您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,了解在 '?, ?, ?,?,?,? 附近使用的正确语法,(SELECT account_id FROM accounts WHERE account_name = ?),?,?,?,UUI' at line 1"}
这是我设置的后端代码:
const Customer = function(customer) {
this.customer_id = customer.customer_id;
this.contact_title = customer.contact_title;
this.contact_first = customer.contact_first;
this.contact_last = customer.contact_last;
this.referral_source = customer.referral_source;
this.initial_contact_date = customer.initial_contact_date;
this.job_title = customer.job_title;
this.account = customer.account;
this.phone = customer.phone;
this.email = customer.email;
this.comments = customer.comments;
this.created_by = customer.created_by;
this.status = customer.status;
}
Customer.create = (newCustomer, result) => {
console.log(newCustomer);
const sql = 'INSERT INTO customers VALUES(UUID_TO_BIN(?, 1),?,?,?,?,?,?,(SELECT account_id FROM accounts WHERE account_name = ?),?,?,?,UUID_TO_BIN(?, 1),?);';
db.query(sql, newCustomer, (err, res) => {
if (err) {
result(err, null);
return;
}
result(null, { id: res.insertId, ...newCustomer });
});
};
我一生都无法弄清楚错误出在哪里,因为它在工作台上有效。任何帮助都会非常感谢,谢谢!
【问题讨论】:
-
您忘记准备语句并添加参数值。
-
如果您要插入所有列,您不应该准备语句吗?这些值来自 newCustomer。 db.query 值为 sql = statement, newCustomer = values
标签: javascript mysql sql node.js