I am looking at some examples in node-mysql https://github.com/felixge/node-mysql
I am confused over when to use ?? and ? as placeholders in constructing a query.
An example is here;
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
How do I know when to use ??
and when to use ?
?
??
is for identifiers. ?
is for values.
values are variables. identifiers are contents of variables or constants.
For more details, see links below
https://github.com/felixge/node-mysql#escaping-query-values https://github.com/felixge/node-mysql#escaping-query-identifiers
Credit goes to t.niese's comment.