I want to query my mysql database in Node for a complete table. The name of the table is supplied via a string from javascript. Mysql throws an error because if I insert it into the query in the following way it results in this error:
'{"code":"ER_PARSE_ERROR","errno":1064,"sqlMessage":"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1$2_Anzahl_der_Anrufe'' at line 1","sqlState":"42000","index":0,"sql":"SELECT * FROM '1$2_Anzahl_der_Anrufe'"}'
let result = [];
tableName = '1$2_Anzahl_der_Anrufe'
connectionData.query('SELECT * FROM ?', [tableName], function (err, res) {
if (err) return callback(err);
if (res.length) {
for (var i = 0; i < res.length; i++) {
result.push(res[i]);
}
}
callback(result);
});
If I try it directly in mysql without the quotes everything works or if insert it directly without the question mark in my js code. How can I escape the quotes?