开发者

Can't access object properties

开发者 https://www.devze.com 2023-02-13 10:33 出处:网络
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 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)...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号