Hi I am trying to run a query but getting the following error: Nodej Mysql2
query
tableName = "some_table"
id = "some_id";
const readForwardedMessageDetails = pool.execute('SELECT * FROM ?? WHERE `id` = ? LIMIT 1',
[tableName, id],
function(err, row) {
if (err) {
console.log(err)
return
} else {
}
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlState: '42000',
sqlMessage: "You have an error in your SQL syntax; check the manual
that corresponds to your MariaDB server version
for the right syntax to use
near '?? WHERE `id` = ? LIMIT 1'
at line 1 ",
sql: 'SELECT * FROM ?? WHERE `id` = ? LIMIT 1'
Was trying from here : Nodejs-Mysql Query table name as a variable
Also use of ?? double question marks for tablename is given here : https://github.com/mysqljs/mysql#preparing-queries
MySql2 suggests it is mostly compatible with mysql so tried the answers above.
https://github.com/sidorares/node-mysql2#history-and-why-mysql2 : MySQL2 is mostly API compatible with mysqljs and supports majority of features. MySQL2 also offers these additional features (hence the inference)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…