codeigniter 中的多个 where 导致 Severity: 4096 错误。带输出

multiple where in codeigniter results in Severity: 4096 error. with output

这是我在 models/action_model.php 文件夹中的 codeigniter 中的代码。结果正确输出但带有

error A PHP Error was encountered Severity: 4096
Message: Object of class CI_DB_mysql_driver could not be converted to string
Filename: models/action_model.php .Error found in line =3 ,line=8,13

控制器功能。

public function search_prof($community="",$gender="",$religion="",$country=""){

if($community  !=""){
    $where = $this->db->where ( 'userprofile.Community', $community, true);
}else{
    $where.="";
}

if($gender !=""){
    $where .= $this->db->where ( 'userprofile.Gender', $gender, true);
}else{
    $where.="";
}
if($religion!=""){
   $where .= $this->db->where ( 'religionlist.Religion_Id', $religion, true);
}else{
   $where.="";
}

 $this->db->select('userprofile.Name,religionlist.Religion_Name,countrylist.Country_Name,userprofile.ProfilePic');
      $this->db->from('userprofile');
      $this->db->join('religionlist', 'userprofile.Religion = religionlist.Religion_Id');
      $this->db->join('countrylist', 'userprofile.Country = countrylist.Country_Id');
                $where;
                 $query = $this->db->get();
if($query->num_rows() ==''){
            return 'failure';       
    }else{
            return $query->result();    
    }

}

->where() 不是 return 字符串。例如,您应该像使用 get() 一样使用它。

更正函数:

public function search_prof($community="",$gender="",$religion="",$country="")
{
    if($community  !="")
         $this->db->where('userprofile.Community', $community, true);

    if($gender !="")
         $this->db->where('userprofile.Gender', $gender, true);

    if($religion!="")    
          $this->db->where('religionlist.Religion_Id', $religion, true);


      $this->db->select('userprofile.Name,religionlist.Religion_Name,countrylist.Country_Name,userprofile.ProfilePic');
      $this->db->from('userprofile');
      $this->db->join('religionlist', 'userprofile.Religion = religionlist.Religion_Id');
      $this->db->join('countrylist', 'userprofile.Country = countrylist.Country_Id');

      $query = $this->db->get();

      return $query->result();    //If no results, it returns false.
}