Reputation: 6433
As the documentation states, I can use the '?' symbol to automatically replace and escape a parameter. The following works as expected:
dbconn.query('SELECT * FROM users WHERE iduser = ?', 11, function(err, results) {
if (err) throw err;
results[0].Password = '';
console.log(results);
res.send(results);
});
But how can I add more parameters? The following does not work:
dbconn.query('SELECT * FROM users WHERE iduser = ? || iduser = ?', 11, 12, function(err, results) {
if (err) throw err;
results[0].Password = '';
console.log(results);
res.send(results);
});
Is this possible and can somebody show me the correct syntax to do so? Thanks
Upvotes: 0
Views: 5552
Reputation: 1611
The correct way is to pass an array:
db.query("SELECT * FROM table WHERE id=? OR id=?", [3, 4], function(err, results) {...
The data in the array is automatically escaped for you. It's all in the docs
https://github.com/felixge/node-mysql
Upvotes: 7