有效请求中的mysqljs ER_PARSE_ERROR

时间:2019-04-03 15:10:49

标签: mysql sql node.js mysqljs

我正在使用mysqljs,并且想删除ID为ID的表格中的一行: class_id是ID(字符串)。

connection.query(
  `DELETE FROM classes WHERE id = ?`, [class_id], (err, result) => {
      if (err) throw(err);
      resolve();
  }
);

连接:

global.connection = mysql.createPool({
  connectionLimit : 10,
  host : config.mysql.hostname,
  user : config.mysql.user,
  password : config.mysql.password,
  database : config.mysql.database,
  charset: 'utf8'
});

但是我得到了这个错误:

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 'DELETE FROM classes WHERE id = 'C2'' at line 1
    at Query.Sequence._packetToError (C:\Users\admin\Documents\main\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
    at Query.ErrorPacket (C:\Users\admin\Documents\main\node_modules\mysql\lib\protocol\sequences\Query.js:77:18)
    at Protocol._parsePacket (C:\Users\admin\Documents\main\node_modules\mysql\lib\protocol\Protocol.js:278:23)
    at Parser.write (C:\Users\admin\Documents\main\node_modules\mysql\lib\protocol\Parser.js:76:12)
    at Protocol.write (C:\Users\admin\Documents\main\node_modules\mysql\lib\protocol\Protocol.js:38:16)
    at Socket.<anonymous> (C:\Users\admin\Documents\main\node_modules\mysql\lib\Connection.js:91:28)
    at Socket.<anonymous> (C:\Users\admin\Documents\main\node_modules\mysql\lib\Connection.js:502:10)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    --------------------

我尝试手动执行请求,效果很好。 有人可以帮我吗?

0 个答案:

没有答案