Trying to query my database and each time I do, it runs all the queries at the end instead of when I need them in nodejs.
var mysql = require('mysql');
var con = mysql.createConnection({
host: database.host,
user: database.user,
password: database.password,
database: database.database
});
The connection data I am pulling from a json file.
function getSymbol(id){
var s = "";
con.query("SELECT * FROM Symbol WHERE PlayerID = '" + id + "'", function (err, result, fields) {
if (err) throw err;
console.log(result);
if (result.length < 1) {
console.log(result);
s = result[0].Symbol;
}
else {
s = "!";
}
});
console.log(s);
return s;
}
It all runs at the end of the program wondering if there is a fix or if I should switch to python (seriously considering rewriting all of it at this point).