mysql - 在 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
})
},
记录被插入到我的数据库中,但服务器因上述错误而停止。在此之前,我没有“完成”参数并且有“完成未定义”错误。
解决方案
推荐阅读
- spring-boot - Kafka 消费者没有选择提到的 Bootstrap 服务器
- java - 无法实例化接口
- sql-server - 为什么表的脏读会导致 SQL Server 2019 中的 WRITELOG 等待?
- c - 分配给变量的最后一个值未使用 [MISRA 2012 规则 2.2,必需]
- python - 如何检测图像中的数字屏幕噪声?(从数字屏幕捕获的图像)?
- ios - UITableViewCell 在其上实现闪烁动画时不可点击
- php - 测试从同一个类调用另一个的静态方法
- tensorflow - 是否有适合分子的 HuggingFace Tensorflow 模型和标记器?
- node.js - 使用 Express Paginate 返回 JSON 响应
- javascript - 推送到数组是返回索引而不是项目(React)