我最近开始将 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”函数无法正常工作。我很乐意为此提供任何解决方案?
最佳答案
您在 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)
关于php - 如何在 codeigniter 中构建事件记录查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12986257/