【问题标题】:Under Codeigniter, is it possible to see mysql_error()?在Codeigniter下,是否可以看到mysql_error()?
【发布时间】:2011-03-15 03:44:44
【问题描述】:

我有一个 Codeigniter 应用程序(使用版本 2.1.0)正在将事务写入 mysql 数据库。我相当确定我发生了外键约束错误,但我找不到让 CI 告诉我具体错误的方法。 mysql_error() 返回为空。

谁能告诉我如何让 Codeigniter 告诉我 mysql 错误消息?

【问题讨论】:

    标签: mysql codeigniter transactions


    【解决方案1】:

    是的,这是 mysql_error() 包装器。

    $this->db->_error_message();
    

    而 mysql_errno 包装器是:

    $this->db->_error_number();
    

    【讨论】:

    • 在当前版本的 CI 中,这些是私有函数。关于通过修改核心文件来访问它们的最佳方式有什么建议吗?
    • 我不明白,我的意思是如何使用它。我试过了,但什么也没显示。 @DRL
    • 我有这个 -> 调用未定义的方法 CI_DB_mysqli_driver::_error_number()。我正在使用 php 5.6
    【解决方案2】:

    你或许可以在db类中使用call_function来访问mysql_error

    http://ellislab.com/codeigniter/user-guide/database/call_function.html

    当然,你也可以在 DB config 中打开 debug 标志,告诉 CI 显示 db 错误:

    http://ellislab.com/codeigniter/user-guide/database/configuration.html

    db_debug - TRUE/FALSE (boolean) - 数据库错误是否应该是 显示出来。

    【讨论】:

    • 当我尝试使用 call_function('mysql_error') 时,我得到以下信息:“此功能不适用于您正在使用的数据库。”是mysql下的innodb表。我在 database.php 配置文件中有 $db['default']['db_debug'] = TRUE 。我得到的最多的是我的异常和堆栈跟踪。这太令人沮丧了。现在,我觉得选择 CI 是一个很大的错误。
    • @pbarney 不要放弃它,检查我的答案
    • 另请注意,正如call_function 页面上所述,您应该传递函数的名称不带 mysql_ 前缀。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-02
    • 1970-01-01
    相关资源
    最近更新 更多