【发布时间】:2014-12-26 14:23:04
【问题描述】:
在 Node.js 中使用 MySql driver,这是我的 ping 方法:
function ping(){
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return false;
}
console.log('connection authenticated: ' + (connection.state == "authenticated"));
console.log('connected as id ' + connection.threadId);
});
console.log("connection: " + connection.state);
return (connection.state == "authenticated");
}
显然,这个 node-mysql 库没有原生的 Ping 方法。我认为这会很好地代替它。但是,我在控制台中看到以下问题:
调试器监听端口 53213
连接:断开
12 月 26 日星期五 2014 年 14:12:38 GMT RazorJS Express 服务器侦听端口 3000
连接已验证:true
连接为 id 17
似乎在连接实际打开之前正在记录连接状态并返回 false。也许这是异步执行的?我怎样才能让它同步运行?
【问题讨论】:
标签: javascript mysql node.js express