且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Codeigniter捕获数据库错误

更新时间:2023-02-08 17:21:33

我试图扩展CI_Exceptions show_error方法来捕获通过'error_db'模板传递的任何错误,而不是通过db驱动程序。

I'd be tempted to extend CI_Exceptions show_error method to catch any errors passed with the 'error_db' template rather than hunting through the db driver.

由于您已使用电子邮件代码扩展CI_Exceptions,这似乎是***做法。

As you've already extended CI_Exceptions with email code this would seem like the best practice.

function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
    set_status_header($status_code);

    $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';

    if ($template == 'error_db')
    {
        // do email send here with $message
    }

    if (ob_get_level() > $this->ob_level + 1)
    {
        ob_end_flush();
    }
    ob_start();
    include(APPPATH.'errors/'.$template.'.php');
    $buffer = ob_get_contents();
    ob_end_clean();
    return $buffer;
}