0
global.ret;
function executeQuery(dbo, sql) {

 
  dbo.query(sql, function (err, result){
    if (err) throw err;
    console.log('first:'+result[1]['idUser']);
    global.ret= result;
  }) ;
  console.log('second:'+global.ret[1]['idUser']);

i am trying to access variable result from outside the function but i dont know how to do that. I tried several things with no success, even global variable do not work ! The first console log always works but never the second one. any help would be great

variable result will get data rows from the database. but getting the result out of the function not working. I tried several affectation with return, all of this not working.

Xaerlur
  • 1
  • 1
  • You need to add more details. What is dbo and the query function it comes with?. And is the second console log not running at all or is it logging "undefined". – Temba Nov 11 '22 at 13:33
  • 1
    `dbo.query` is asynchronous and you can ONLY therefore access the result inside the callback you supply. – Ben Aston Nov 11 '22 at 13:34

0 Answers0