gpt4 book ai didi

mysql - Node mysql变量比较

转载 作者:行者123 更新时间:2023-11-29 18:28:54 25 4
gpt4 key购买 nike

嗨,我正在做一个小项目,但我陷入了困境。我想做的是将mysql行与变量进行比较,以从数据库中获取用户steamid(函数winner_daily)(对不起我的英语:()。这里是我的代码

var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit : 10,
host : 'localhost',
user : 'root',
password : '*****',
database : 'bet'
});

pool.query("SELECT `name` FROM `users` WHERE levels >= 3 ", function (error, results, fields) {
if (error) throw error;
var rand = results[Math.floor(Math.random() * results.length)];

winner_daily(rand);


});
function winner_daily(winner){

console.log("And the winner is :",winner);
pool.query(`SELECT steamid FROM users WHERE name = ${mysql.escape(winner)}`, function (error, row, fields) {
if (error) throw error;

console.log(row)
});

}

最佳答案

 console.log("And the winner is :",winner);

pool.query('SELECT * FROM `users` WHERE `name`=' + winner.name, function (error, row) {
if (error) throw error;
if(!row.length) console.log('There is not any row'); return false;

console.log(row)
});

您需要在查询中传递获奖者姓名。

关于mysql - Node mysql变量比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45895277/

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