Im trying to build an app which requires that I make more than one query per view/controller.
Im trying to do the asynchronously using a nested structure, but the sql result comes up undefined in the inner closure.
This is the function Im using to do this:
var conn = db.config(mysql);
function run_queries(conn,callback) {
conn.query(sql1, var1, function(err, res1) {
if(err){ callback(err); return; }
console.log(res1); // RETURNS SUCCESSFULLY!
conn.query(sql2, var2, function(err, res2) {
if(err){ callback(err); return; }
console.log(res2); // UNDEFINED :(
callback(null, res2);
});
});
}
run_queries(conn,function(err, result){
console.log(result); // UNDEFINED :(
});
I have checked my SQL and it is without errors. If I swap sq1 with sq2, the outer closure returns the correct query for sq2.
The inner closure just isnt returning a query.