我最近开始将我的codeigniter应用程序中的后端查询转换为活动记录模式。截至目前我正在使用codeigniter 2.1版本。我最初在mysql中编写了一个查询
SELECT * FROM table WHERE (field1 = $field1 OR field2 = $field2) AND field3 = $field3 AND field4 = 'text'
现在我想以下面给出的方式写这个东西:
$this->db->select('*');
$this->db->from('table');
$this->db->where('field1',$field1);
$this->db->or_where('field2',$field1);
$this->db->where('field3',$field2);
$this->db->where('field4','text');
但不知何故,“or_where”功能无法正常工作。对此有任何解决方案,我会很高兴吗?
答案 0 :(得分:2)
您在Active Record
$where = "(field1 = " . $field1 . " OR field2 = " . $field2 . ") AND
field3 = ". $field3 . " AND field4 = 'text'";
$this->db->where($where);
Click here for source: Active Record (and browse for custom string)