1.查询的条件按mysql的语法顺序编码,相同的操作放一起
2.要查询的字段写明白。尽量少用或不用*;
----------------------------------------------
参照mysql 语法
select field1,field2 from table where 1 group by field1 order by field2 asc limit 5;
CI写法(Active Record 模式):
$this->db->select('tabl1.f1,tabl1.f2');
$this->db->select('table2.f3,table2.f4');
$this->db->join('table2', 'table2.id = tabl1.id','left');
$this->db->where(array("table2.f1"=>"xxx"));
$this->db->order_by('tabl1.f1','asc');
$this->db->group_by('table2.f2');
$this->db->limit(5);
$this->db->get('tabl1');
本文介绍如何使用CodeIgniter(CI)的ActiveRecord模式构建复杂的数据库查询。通过具体示例展示了如何选择字段、联接表、设置查询条件、排序、分组及限制返回结果等操作。
1335

被折叠的 条评论
为什么被折叠?



