【问题标题】:Cannot read property 'insertId' of undefined in NodeJS with MySQL无法使用 MySQL 在 NodeJS 中读取未定义的属性“insertId”
【发布时间】:2021-09-12 11:03:07
【问题描述】:

我正在尝试从 NodeJS 中的异步等待 MySQL 查询中获取 insertId。我已经去下面的代码;

    row_a = await db.query( 'INSERT INTO audioposts (title,userid,opid) VALUES (?,?,? )', [title,userid,opid]);   
    
    var newid = row_a[0].insertId;

但是我收到了这个错误;

  Cannot read property 'insertId' of undefined

我的语法有问题吗?

【问题讨论】:

  • 查询运行后row_a的值是多少?

标签: mysql node.js async-await promise node-mysql


【解决方案1】:

原来我可以做到这一点;

  var newid = row_a.insertId;

【讨论】:

    猜你喜欢
    • 2016-01-07
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多