javascript - 如何获取mysql连接检查回调函数的返回数据?

标签 javascript mysql node.js

我无法从nodejs的mysql连接检查功能获取返回数据。输出始终为 false。

var dbcheck = false;

connection.connect(function (err) {
    if(err) {

        dialog.showMessageBox(null,dbOptions, function (response) {

            if(response == 1){
                shell.openExternal("https://innoscript.co");
                app.quit();
            }

            if(response == 0){ app.quit(); }
        });
    }

    if(!err){
        dbcheck = true;
        return dbcheck;
    }

});

console.log(dbcheck);

最佳答案

您的 console.log() 在连接发生之前执行。

您应该在回调函数内使用 console.log() 。

关于javascript - 如何获取mysql连接检查回调函数的返回数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54926783/

相关文章:

node.js - Nodeclipse + nodemon错误

node.js - 从回调外部调用变量nodejs

javascript - webkit-transform 覆盖 Chrome 13 中的 z-index 排序

mysql - 尝试使用 phpMyAdmin 创建 MySQL 触发器,但出现 MySQL 错误 #1422

mysql - 如何按列分组,并选择任意非空其他列来显示

php - 从 mysql 创建 excel 并在 php 中将其作为附件电子邮件发送

node.js - 如何为 Angular 5/nodejs 启用 Access-Control-Allow-Origin?

javascript - Apps 脚本关于循环的奇怪行为

IE7 和 IE8 中的 JavaScript 错误 : SCRIPT5007: Unable to get the value of property 'newQuestion' : object is null or undefined

javascript - Vue.js[vuex] 如何从突变中调度?