gpt4 book ai didi

mysql - 调用退出后, Node Mysql 无法将查询入队

转载 作者:IT老高 更新时间:2023-10-28 22:03:38 24 4
gpt4 key购买 nike

在哪里关闭 mysql 连接?

我需要按顺序运行查询。我目前正在编写如下代码:

var sqlFindMobile = "select * from user_mobiles where mobile=?";
var sqlNewUser = "insert into users (password) values (?)";
//var sqlUserId = "select last_insert_id() as user_id";
var sqlNewMobile = "insert into user_mobiles (user_id, mobile) values (?,?)";
connection.connect(function(err){});
var query = connection.query(sqlFindMobile, [req.body.mobile], function(err, results) {
if(err) throw err;
console.log("mobile query");
if(results.length==0) {
var query = connection.query(sqlNewUser, [req.body.password], function(err, results) {
if(err) throw err;
console.log("added user");
var user_id = results.insertId;
var query = connection.query(sqlNewMobile, [user_id, req.body.mobile], function(err, results) {
if(err) throw err;
console.log("added mobile");
//connection.end();
});
});
}
});
//connection.end();

(我是node、npm-express和npm-mysql的初学者。我试过搜索“express mysql cannot enqueue”以找到相关问题,但没有找到。)

最佳答案

我用这个方法解决了这个问题:

connection.end() 在您的 connection.query 函数中

固定代码是here

关于mysql - 调用退出后, Node Mysql 无法将查询入队,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14333272/

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