【问题标题】:How to redirect page to some other page if Database Error Occurs如果发生数据库错误,如何将页面重定向到其他页面
【发布时间】:2014-07-09 23:01:15
【问题描述】:

我在一个表上应用了复合主键,如果主键约束失败,它会返回错误消息, 因此,每当用户输入重复的行时,程序都会抛出以下错误消息。

Duplicate entry '43-15' for key 'uk_sid_coursid'

我想跳过此错误消息,我希望页面重定向到另一个页面myerror.php,用户可以返回并更新记录。我使用了if-else 条件,但它仍然给我同样的错误信息。以下是我的代码,请查看。

型号

    public function student_marks_fill($student_id, $semester_course_id)
    {
        $data= array(
            "StudentId"=> $student_id,
            "SemisterCourseId"=>$semester_course_id
        );

        if($this->db->insert('student_marks', $data))
        {
            return true;
            }
            else
            {
                return false;
                }

        }   

控制器

            if($this->loginmodel->student_marks_fill($id, $semesterCourseId))
            {
                $this->load->view('admin');
                }
                else
                {
                    $this->load->view('admin');
                    }

            }   

【问题讨论】:

    标签: php html mysql codeigniter redirect


    【解决方案1】:

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

    config/database.php 中将db_debug 设置为FALSE

    $db['default']['db_debug'] = FALSE;
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      • 2023-04-09
      • 2014-08-27
      • 1970-01-01
      • 2020-06-08
      • 1970-01-01
      相关资源
      最近更新 更多