Query a connection object with parameters

suggest change

Put 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.');
  }
});

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents