Skip to content Skip to sidebar Skip to footer

Remove Slashes In Node Js Mysql Query

This is my code. pool.getConnection(function (err, connection) { connection.query('delete from userFiles where type = 1 and typeId = ' + taskId +

Solution 1:

You're not supposed to add the quotes yourself around the ? placeholder. Remove them.

You should also pass an array, not a string. Assuming it's a clean string, you can just use split.

connection.query(
      "delete from userFiles where type = 1 and typeId = " + taskId +
      " and fileName NOT IN (?) ", [oldFileNames.split(/,\s*/)],
      function (err, rows) {

Solution 2:

A possible solution is to use connection.escape();

connection.query("delete from userFiles where type = 1 and typeId = " + taskId + " 
and fileName NOT IN (" + connection.escape(oldFileNames) + ")");

Post a Comment for "Remove Slashes In Node Js Mysql Query"