I have a query like below:
connection.query('SELECT * FROM `Users` WHERE `Id` = ?;', [Id], function (err, row) {
var a = row;
});
//how can I use variable `a` in here?
I have a query like below:
connection.query('SELECT * FROM `Users` WHERE `Id` = ?;', [Id], function (err, row) {
var a = row;
});
//how can I use variable `a` in here?
you really won't be able to. at least not easily.
var a;
connection.query('SELECT * FROM `Users` WHERE `Id` = ?;', [Id], function (err, row) {
a = row;
});
//execute stuff
This will accomplish getting the value out into the next scope but where you would //execute stuff
will have already happened before a is set. This is because (I'm assuming) node-mysql is asynchronous.