var data;
function initM(){
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database:"ns2"
});
sql="SELECT id,first_name,last_name from stu_details";
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
con.query(sql,function (err, result)
{if (err) throw err;
data=result;//----> I want to save the returned result from the query in "data"
console.log(result);//--> prints the data of query
});
});
}
console.log(initM());
console.log(data);//--> prints "undefined"
I want to save the returned result from the query in a variable and use it in another function. prints "undefined" tanks!