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());
尽管此类列存在一个元组,但查询返回的是一个空数组。 我如何在查询中使用局部变量?
最佳答案
你可以使用 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);
关于mysql - sync-mysql node js中使用变量调用query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51183840/