首页 > 解决方案 > 在 Node 中向 DB 插入记录时重新抛出非 MySQL 错误

问题描述

我正在使用 node.js 并在将记录插入数据库时​​出现以下错误:

\node_modules\mysql\lib\protocol\Parser.js:437
      throw err; // Rethrow non-MySQL errors
      ^
OkPacket {
  fieldCount: 0,
  affectedRows: 1,
  insertId: 9,
  serverStatus: 2,
  warningCount: 0,
  message: '',
  protocol41: true,
  changedRows: 0
}

在执行以下代码时

createCard: function( card, card_type, card_url, callback){
    connection.query('INSERT INTO cards (card, card_type, url)' +
    ' VALUES ("'+ card+'", "'+card_type+'", "'+card_url+'")', function(done,err,rows,fields){
        if (err) throw err;
        callback(rows.insertId); // returns the id of the card just created
    })
  },

记录被插入到我的数据库中,但服务器因上述错误而停止。在此之前,我没有“完成”参数并且有“完成未定义”错误。

标签: mysqlnode.js

解决方案


推荐阅读