Search code examples
node-mysql

What is the difference between single ( ? ) and double question mark ( ?? ) in node-mysql?


Am sure this is fairly obvious, to me it would make more sense if the second double question mark in the example was a single one.

From their docs:

Alternatively, you can use ?? characters as placeholders for identifiers you would like to have escaped like this:

var userId = 1;
var columns = ['username', 'email'];
var query = connection.query('SELECT ?? FROM ?? WHERE id = ?', [columns, 'users', userId], function(err, results) {
  // ...
});

console.log(query.sql); // SELECT `username`, `email` FROM `users` WHERE id = 1

Solution

  • ?? is used for table and column names, it escapes them with backticks. ? is for ordinary values.