【问题标题】:MySQL and NodeJsMySQL 和 NodeJs
【发布时间】:2019-07-15 23:01:39
【问题描述】:

我正在尝试将我的代码链接到我的数据库,但我不断收到此错误。我在端口 localhost:8080 远程端口 80 上使用 mac 和 XAMPP。我无法想象为什么我不断收到此错误。代码似乎是正确的。希望有人可以帮助我,因为我的讲师不在,我希望能理解这一点并让它发挥作用。我的数据库似乎也设置正确。还有一些信息我手动放入表格中,希望它会出现在http://localhost:3000

https://github.com/kamrantrea/serverSide2019-/tree/master/tutorial/weekFive

未定义 /Users/admin/Desktop/nodejsmysqltest/routes/index.js:8 connection.query(SELECT * FROM users ORDER BY id DESC, function (err, rows, fields) { ^ TypeError:无法读取未定义的属性“查询”

【问题讨论】:

    标签: mysql node.js database xampp localhost


    【解决方案1】:

    似乎 getConnection 调用了您的回调并出现错误。尝试在回调函数开头添加错误检查:

        req.getConnection(function(err, connection) {
          if (err) return next(err);
    

    由于代表不足,将其发布为答案而不是评论

    【讨论】:

    • 抛出错误; // 重新抛出非 MySQL 错误 ^ ReferenceError: err is not defined .这是我现在遇到的错误
    猜你喜欢
    • 2016-12-06
    • 2019-04-20
    • 1970-01-01
    • 2014-05-24
    • 2021-04-27
    • 1970-01-01
    • 2013-02-21
    • 2020-08-20
    • 2023-03-27
    相关资源
    最近更新 更多