【问题标题】:Need help triggering a database error需要帮助触发数据库错误
【发布时间】:2015-06-12 19:33:01
【问题描述】:

我正在使用 CodeIgniter $db->insert 函数来执行插入操作。但我试图弄清楚如何触发查询错误以查看系统是否记录错误消息。

我试图拼错表格名称,但这不起作用..它只会在页面上显示一条错误消息。

关于如何执行虚假错误的任何想法?下面是我的代码..

任何帮助将不胜感激!

 public function newMsgTemplate($template_name, $body){


        try {

            $this->db->insert("message_template", ['template_name' => $template_name, 'body' => $body]);
            trigger_error("error");
        } catch (Exception $e){

            log_message("error", "There was an error when trying to preform the query ");

        }

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    尝试自己抛出异常。

    public function newMsgTemplate($template_name, $body){
        try {
            $this->db->insert("message_template", ['template_name' => $template_name, 'body' => $body]);
            trigger_error("error");
            throw new MyException('foo!');
        } catch (Exception $e){
    
            log_message("error", "There was an error when trying to preform the query ");
    
        }
    

    Source

    【讨论】:

    • 知道了。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2011-09-02
    相关资源
    最近更新 更多