Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node Mysql Cannot Enqueue a query after calling quit

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(); 

(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.)

like image 264
Kinjal Dixit Avatar asked Jan 15 '13 07:01

Kinjal Dixit


1 Answers

I fixed this problem use this method:

connection.end() in your connection.query function

The fixed code is here

like image 120
unlimited Avatar answered Sep 22 '22 18:09

unlimited