Php 需要帮助触发数据库错误吗

Php 需要帮助触发数据库错误吗,php,mysql,codeigniter,Php,Mysql,Codeigniter,我正在使用CodeIgniter$db->insert函数来执行插入。但是,我试图找出如何触发查询错误,以查看系统是否记录错误消息 我试图拼错表名,但那不起作用。它只会在页面上显示一条错误消息 有没有关于我如何制造假错误的想法?下面是我的代码 任何帮助都将不胜感激 public function newMsgTemplate($template_name, $body){ try { $this->db->insert("message

我正在使用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 ");

        }

尝试自己抛出异常

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 ");

    }

明白了。谢谢