MySQL查询VALUES($ 1,$ 2)[req.body.number1,req.body.number2]无法正常工作吗?

时间:2020-05-16 20:13:04

标签: mysql node.js express

此查询有什么问题,如果我用实际值替换$ 1,$ 2,$ 3,$ 4,$ 5

这是我的代码。

  let queryText = "INSERT INTO`calculator_challenge`.`calculations`
(`number1`, `operator`, `number2`, `total`, `created_at`) 
VALUES ($1, $2, $3, $4, $5);";

  pool.query(queryText, [calc_obj.number1, calc_obj.operator, calc_obj.number2, calc_obj.total, calc_obj.created_at], (error, result, fields) => {
    if (error) throw error;
    res.send(JSON.stringify(result));
  });
});

1 个答案:

答案 0 :(得分:0)

按如下所示更新代码:(我加上了一些引号)

let queryText = "INSERT INTO`calculator_challenge`.`calculations`(`number1`, `operator`, `number2`, `total`, `created_at`) VALUES ('$1', '$2', '$3', '$4', '$5')";