var mysql= require('sync-mysql');
var connection = new mysql({
host: 'host-name',
user: 'root',
password: 'password',
database: 'tables', //name of the database
multipleStatements: true
});
var val="value"
const ans= connection.queueQuery("Select * from table Where col_1=val";);
console.log(ans());
尽管存在用于此类列的元组,但查询返回的是空数组。 如何在查询中使用局部变量?
答案 0 :(得分:0)
您可以使用ES6 Template literals:
const ans = connection.queueQuery(`Select * from table Where col_1 = ${val}`);
或简单的串联:
const ans = connection.queueQuery('Select * from table Where col_1 = ' + val);