have u got an idea how can i take out RESULTS outside od CONNECT function?
var bike;
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost", // ip address of server running mysql
user: "root", // user name to your mysql database
password: "", // corresponding password
database: "sociale" // use the specified database
});
// make to connection to the database.
con.connect(function(err) {
if (err) throw err;
// if connection is successful
con.query("SELECT * FROM bikes", function (err, result, fields) {
// if any error while executing above query, throw error
if (err) throw err;
// if there is no error, you have the result
bike = result;
console.log(bike);//WORKS
});
console.log(bike);//DOESNT WORK
});
I tried making global variable but it doesn't work outside of query function