CI ActiveRecord中的组合条件

时间:2013-08-07 09:42:25

标签: php mysql codeigniter activerecord

我想做一个像

这样的SQL查询
select * where x = 10 and (y=12 or h=15)

如何以CI ActiveRecord格式实现这一目标?

2 个答案:

答案 0 :(得分:1)

请参阅Active record参考

$where="x = 10 and (y=12 or h=15)";
$this->db->select('*');
$this->db->from('mytable');
$this->db->where($where);
$query = $this->db->get();

答案 1 :(得分:0)

尝试

$sql = "SELECT * FROM TABLE_NAME WHERE x = 10 AND (y = 12 OR h = 15)";
$result = $this->db->query($sql);

或者喜欢

$this->db->select('*');
$this->db->from('TABLE_NAME');
$this->db->where('x',10);
$this->db->AND('y',12);
$this->db->or_where('h',15);
$query = $this->db->get();