gpt4 book ai didi

mysql - sync-mysql node js中使用变量调用query

转载 作者:行者123 更新时间:2023-11-30 21:41:51 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com