node js mysql escape string
snippet in javascript

node js mysql escape string

user1087

// Escape values:

let escaped = mysql.escape('myString');

// or

mysql.query(
  "SELECT * FROM `table` WHERE `str1`=? AND `str2`=?",
  ['myString1', 'myString2'],
  (err, result)=>{}
);

// Escape identifiers:

mysql.query(
  "SELECT * FROM ??",	// note the double ?
  ['tablename'],
  (err, result)=>{}
);