节点mysql调用quit后无法使查询入队 [英] Node Mysql Cannot Enqueue a query after calling quit
本文介绍了节点mysql调用quit后无法使查询入队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在哪里关闭mysql连接?
where do i close the mysql connection?
我需要按顺序运行查询.我正在编写目前看起来像这样的代码:
I need to run queries in sequence. I am writing code that looks like this at present:
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();
(我是节点,npm-express和npm-mysql的初学者.我曾尝试在SO中搜索"express mysql无法入队"以查找相关问题,但未找到它们.)
(I am a beginner with node, npm-express and npm-mysql. I have tried searching SO for "express mysql cannot enqueue" to find related questions and have not found them.)
推荐答案
我使用此方法解决了此问题.
I fixed this problem use this method.
connection.end()在您的connection.query函数中
固定代码为 here
The fixed code is here
这篇关于节点mysql调用quit后无法使查询入队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文