我从数据库中获取了一些数据,但现在我想将它们传递给另一个变量。此变量位于getData函数之上。
var storeData;
function getData () {
connection.connect();
var query = connection.query('SELECT * FROM users', function(err, results) {
if(err) throw err;
console.log(results); // Here is OK. I have all data (results is typeof object)
storeData = results; // Not working
});
connection.end();
}
getData ();
console.log(storeData); // undefined