Javascript INSERT INTO语句在使用mySQL的NodeJS中不起作用

Javascript INSERT INTO语句在使用mySQL的NodeJS中不起作用,javascript,mysql,sql,node.js,Javascript,Mysql,Sql,Node.js,我一直在拼命想弄清楚mySQL语法的问题。我得到了一个错误: {消息:您的SQL语法有错误;请检查与您的MySQL服务器版本对应的手册,以了解在“?、?、?、?、?、?、?、?、?”附近使用的正确语法,从第1行的accounts_name=?、?、?、?、UUI”中选择account_id 以下是我在后端设置的代码: const Customer = function(customer) { this.customer_id = customer.customer_id; this.co

我一直在拼命想弄清楚mySQL语法的问题。我得到了一个错误:

{消息:您的SQL语法有错误;请检查与您的MySQL服务器版本对应的手册,以了解在“?、?、?、?、?、?、?、?、?”附近使用的正确语法,从第1行的accounts_name=?、?、?、?、UUI”中选择account_id

以下是我在后端设置的代码:

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 });
  });
};

我一辈子都搞不清楚错误在哪里,因为它是在工作台上工作的。任何帮助都将不胜感激,谢谢

事实上我自己找到了答案。我试图使用一个对象,认为这些值将被放入语句中。只需使用Object.values创建一个新变量并将其放入数据库函数。

您忘记了准备语句和添加参数值。如果要插入所有列,您不必准备语句,对吗?价值观来自新客户。db.query的值是sql=statement,newCustomer=value