I am using NodeJS and node-mysql, I've created a DB layer to allow easy integration with other DBs (example MongoDB) for later use. At this point in time, the syntax is essentially the same as MySQL.
I am placing a call to the query object of MySQL, and it's returning the results to my callback func开发者_运维技巧tion, which I can send to the console with console.log, and it shows the following:
[ { username: 'test', total: 1 } ]
Yet, when I try to access the total, it says undefined. Here's my code:
db.query("SELECT username, COUNT(user_id) AS total FROM users WHERE username = '" + message.username + "'", function(err, info) {
console.log(info);
self.sendRequest(client, '{ "command" : "CALLBACK", "result" : ' + info.total + ' }');
});
when using console.log(info), it returns valid JSON syntax, however I cannot access the total via info.total, as it returns undefined....
Any ideas on why I'm having this issue? If you need to see more code I will be happy to provide it..
Figured it out;
info[0].total
returns what I need (d'oh)...
精彩评论