1

I'm using mysqljs and I want to delete a row in a table with its id: class_id is the id (string).

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

Connection:

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

But I got this error:

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

I tried to execute the request manually and it works great. Can someone help me?

Romain C
  • 11
  • 1
  • 3

0 Answers0