Global variable doesn’t change js [duplicate]

function get_info()
{
  var temp;
  con.connect(function (err) {
    if (err) throw err;
    con.query("SELECT * FROM customers", function (err, result, fields) {
      if (err) throw err;
      temp = result;
      console.log(temp);
    });
  });
  console.log(temp);
}

when I run the function, the console.log(temp) at the end of the function shows “undefined” even though it shows the data when I do console.log(temp) in the inside function. I think the problem is that the global variable doesn’t change but I don’t know how to fix it. Any ideas?