MySQL 5.6.41错误号1064:使用变量创建MySQL查询

MySQL 5.6.41错误号1064:使用变量创建MySQL查询,mysql,node.js,express,Mysql,Node.js,Express,我目前有一个localhost,但很快就要通过AWS Node.JS服务器与Express一起运行了,当我遇到以下错误时,我正试图通过MySQL查询更新一个RDS实例: { [Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''his

我目前有一个localhost,但很快就要通过AWS Node.JS服务器与Express一起运行了,当我遇到以下错误时,我正试图通过MySQL查询更新一个RDS实例:

{ [Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''history0' = 'http://localhost:3000/' WHERE id = 1' at line 1]
  code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlMessage: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'\'history0\' = \'http://localhost:3000/\' WHERE id = 1\' at line 1',
  sqlState: '42000',
  index: 0,
  sql: 'UPDATE infected SET \'history0\' = \'http://localhost:3000/\' WHERE id = 1;' }
导致错误的POST请求:

app.post('/history', function(req, res) {
  var hist = 'history' + 0;
  var sql = 'UPDATE infected SET ? = ? WHERE id = ?;';
  connection.query(sql,  [hist, req.body[0].url, 1]);
});
我使用hist作为变量,因为我计划将它放在一个循环中,但我不确定我在这里声明它的方式是否导致了这个问题,所以我将它保持原样。req.body是调用chrome.history.search时调用的JSON.stringify的输出。因此,我试图获取索引0处条目的URL

我已尝试使用硬编码字符串直接调用connection.query,如下所示:

connection.query("UPDATE infected SET history0='google.com' WHERE id='1'");

并且它成功地更新了数据库,所以我发现如何使用问号将变量hist和req.body[0].url插入查询中存在问题,但我无法找出问题所在。

尝试使用double??对于键,按以下方式:

app.post('/history', function(req, res) {
  var hist = 'history' + 0;
  var sql = 'UPDATE infected SET ?? = ? WHERE id = ?;';
  connection.query(sql,  [hist, req.body[0].url, 1]);
});