node-mysql中的单问号(?)和双问号(??)有什么区别?

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

我敢肯定这很明显,对我来说,如果示例中的第二个双问号是单个问号会更有意义。

来自他们的 docs:

或者,您可以使用 ??字符作为您希望像这样转义的标识符的占位符:

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

?? 用于 table 和列名,它用反引号转义它们。 ? 用于普通值。

Barmar 是对的,但我在这里举个例子。

??用于table名称和列名?用于普通值,如where子句中的参数值。

let insertQuery = 'INSERT INTO ?? (??,??) VALUES (?,?)';
let query = mysql.format(insertQuery,["todo","user","notes",data.user,data.value]);
pool.query(query,(err, response) => {
    if(err) {
        console.error(err);
        return;
    }
    // rows added
    console.log(response.insertId);
});

In the above example, first three ?? mark take table name and column name (todo is the table name and user, notes are the column name). Last two ? take normal values those will be plain data used to be inserted into todo table.