【问题标题】:How can I know if the data was updated in mysql database or an error had occured如何知道mysql数据库中的数据是否已更新或发生错误
【发布时间】:2014-07-30 12:46:46
【问题描述】:

我建立了一个网站。我的服务器端是用节点(express)编写的。 我使用连接到 mysql 数据库来更新数据。 更新是通过调用存储过程来完成的。 连接是:

connection.query("call update_user(?)",id,
        function(err, results)
        {
            connection.release();
        });
    }
});

我想知道结果对象包含什么。 当我记录它时:

console.log(result);

我得到输出:“[Object object]”。

这不是我想要的。

那么结果对象的属性是什么?

【问题讨论】:

  • 如果您使用console.dir 而不是console.log 会怎样?这 result 与您发布的代码 sn-p 中的 results 也不同吗?
  • 谢谢,但我有一个错误:当我登录时:console.log(result);输出是没有引号的 [Object object]。当我使用 console.dir 时,输出是“[Object object]”。我想知道结果的属性是什么。
  • 如果这是输出,那么听起来您的 result 变量包含字符串文字 '[Object object]' 而不是实际对象。你如何分配resultresult = results[0] 或其他?
  • 我尝试记录结果[0],但未定义。
  • 可以显示update_user()存储过程的内容吗?

标签: mysql node.js stored-procedures


【解决方案1】:

我不知道发生了什么变化,但它突然起作用了! 当我记录结果时,我得到:

{ fieldCount: 0,
affectedRows: 1,
insertId: 0,
serverStatus: 2,
warningCount: 0,
message: '',
protocol41: true,
changedRows: 0 }

所以我知道数据是否发生了变化。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-27
    • 2018-08-24
    相关资源
    最近更新 更多