Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在codeigniter中使用自定义where子句_Php_Mysql_Sql_Codeigniter - Fatal编程技术网

Php 在codeigniter中使用自定义where子句

Php 在codeigniter中使用自定义where子句,php,mysql,sql,codeigniter,Php,Mysql,Sql,Codeigniter,我的活跃记录是 $ql = $this->db->select('course_id')->from('tbl_course_choice')->where('course_id',$course_id)->get(); if( $ql->num_rows() > 0 ) { $data = array( 'teacher_name_1' => 'mehdi' ); $thi

我的活跃记录是

$ql = $this->db->select('course_id')->from('tbl_course_choice')->where('course_id',$course_id)->get();

    if( $ql->num_rows() > 0 ) {
        $data = array(
        'teacher_name_1' => 'mehdi'
        );
        $this->db->where('teacher_name_1', NULL);
        $this->db->where('course_id', $course_id);
        $this->db->update('tbl_course_choice', $data);
    } else {
        $a = array(
            'course_id' => $course_id,
            'course_code' => $course_code,
            'course_title' => $course_title,
            'course_type' => $course_type,
            'credit_hours' => $credit_hours,
            'contact_hours' => $contact_hours,
            'section' => $section,
            'teacher' => $teacher, 
            'pre_requisite' => $pre_requisite,
            'year' => $year,
            'semester' => $semester,
            'offering_year' => $offering_year,
            'offering_session' => $offering_session,
            'teacher_name_1' => $teacher_name_1


            );
        $this->db->insert('tbl_course_choice', $a);
    }
我需要检查文件是否为空,然后插入或更新其他文件,否则插入其他文件

    if {
    $this->db->where('teacher_name_1', NULL);
    $this->db->where('course_id', $course_id);
    $this->db->update('tbl_course_choice', $data);
} 
elseif {
    $this->db->where('teacher_name_1', IS NOT NULL);
    $this->db->where('teacher_name_2', NULL);
    $this->db->where('course_id', $course_id);
    $this->db->update('tbl_course_choice', $data);
}
如何检查是否为空,然后插入或更新。任何人都可以帮助我???

使用自定义字符串

$this->db->where('teacher_name_1 IS NULL', NULL, FALSE);

我尝试了,但没有工作,似乎无法检查字段是否为空,任何其他检查字段是否为空的方法在我的情况下,其工作方式如下$this->db->where('teacher\u name\u 1!=','');