Query a connection object with parameters
suggest changePut user-supplied values in parameters, not in the SQL string. This example searches for the user aminadav. The ? placeholder is the mysql / mysql2 style:
var username = 'aminadav';
var querystring = 'SELECT name, email from users where name = ?';
connection.query(querystring, [username], function(err, rows, fields) {
if (err) throw err;
if (rows.length) {
rows.forEach(function(row) {
console.log(row.name, 'email address is', row.email);
});
} else {
console.log('There were no results.');
}
});
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents