Answer the question
In order to leave comments, you need to log in
Node.js + mysql nested queries, where is the error?
Tell me what's wrong? I can't figure out if the code seems to be correct, but the second request doesn't work.
throws an error: Cannot enqueue Query after invoking quit
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'vchat'
});
connection.query('SELECT * from therooms', function(err, rows, fields) {
if (!err){
connection.query('SELECT roomid from therooms', function(errw, rowsw, fieldsw) {
if (!errw){
console.log('INNER RESULT: '+rowsw);
}else{
console.log('2Error while performing Query.'+errw);
}
});
}else{
console.log('1Error while performing Query.');
}
});
Answer the question
In order to leave comments, you need to log in
The solution is:
It was necessary to remove connection.end() after the first connection.query().
The connection was closed and the second asynchronous call was triggered after the connection was closed.
Therefore, the connection must either be closed correctly (inside connection.query), or not closed at all if the script is running all the time
try
https://github.com/felixge/node-mysql#pooling-conn...
But why do you need a muscle on a node anyway? all these requests .. not too lazy to write them? simpler than monga, where the same JS is used
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question