node-mysql where does connection.end() go

后端 未结 2 1972
悲哀的现实
悲哀的现实 2021-02-12 13:11

I am really confused with using connection.end() in node-mysql.

I don\'t fully understand where it goes, at the moment i place it after a query but then if i create a ne

2条回答
  •  时光说笑
    2021-02-12 13:44

    socket.on('connect', function(data,callBack){
           var session = sanitize(data['session']).escape();                    
    
           var query = connection.query('SELECT uid FROM sessions WHERE id = ?', [session],
               function(err,results){
               if(err){ 
                      console.log('Oh No! '+err);                   
                  }else{
                      io.sockets.socket(socket.id).emit('connectConfirm',{data : true});
                  }
    
               });
    
           connection.end(); // close connection outside the callback
       });
    

    Its giving error because you are closing connection during en-queue

提交回复
热议问题