我有一个使用node-mysql查询MySQL数据库的node.js应用程序。MySQL查询中的变量导致错误
问题:看来,当我在查询中的表名称变量,事情停止工作。我错过了什么吗?
工作节点代码
client.query('SELECT * from tableA',
function(error, results, fields) {
if (error)
throw error;
callback(results);
});
非工作节点代码
client.query('SELECT * from ?',
[ tableA ],
function(error, results, fields) {
if (error)
throw error;
callback(results);
});
表名通常不能作为参数传递。您需要使用动态SQL。 –
可能重复[*在mysql sproc *中使用表名的变量](http://stackoverflow.com/questions/2754423/use-a-variable-for-table-name-in-mysql-sproc)和[ *在MySQL中:如何传递一个表名作为存储过程和/或函数参数?*](http://stackoverflow.com/questions/2977356/in-mysql-how-to-pass-a-table-name- as-stored-procedure-and-or-function-argument) – mellamokb