I have trouble figuring out how to get the data from mysql Queries in the callback function. For example I have the query as follows:
mysqlConnection.query('SELECT COUNT(*) from card AS count', function (err, result) {
if (err) {
throw err;
}
else {
console.log(Type.of(result));
console.log("card count is as: " + result.count);
console.log("Card count is: " + result["COUNT(*)"]);
console.log(result);
}
});
This prints out:
[Function: Array]
card count is as: undefined
Card count is: undefined
[ { 'COUNT(*)': 3 } ]
What is a "[Function: Array]" datatype and how do you pick variables from it? An array of functions? Why is "result.count" undefined even though I in the query I use the AS thing.
Also how is the following query different from the one below it?
mysqlConnection.query('SELECT COUNT(*) from card AS count', function (err, rows, fields) {
});
mysqlConnection.query('SELECT COUNT(*) from card AS count', function (err, result) {
});
When do I use the other and when the other one?