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 (?,?)";
var query = connection.query(sqlFindMobile, [], 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,], function(err, results) {
                if(err) throw err;
                console.log("added mobile");

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

1/15/2013 7:53:17 AM

I fixed this problem use this method.

connection.end() in your connection.query function

The fixed code is here

3/7/2013 9:11:45 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow