|
本帖最后由 张三的歌 于 2016-8-19 09:32 编辑
以下代码都是在model层的东西
public function getSomeFieldsByWhere($where, $fields, $num, $offset){
$sql = "SELECT {$fields} FROM {$this->_table} {$where} LIMIT {$offset}, {$num}";
//die($sql);
$query = $this->db->query($sql);
$res = $query->result_array();
return $res;
}
上面这种肯定是不防止注入的,但是用起来方便,因为where里面可以随便写,比如order by , group by, like等等
public function getAllFieldsByWhere($fields,$where=array(),$num,$offset){
//字段
$this->db->select($fields);
$query = $this->db->get_where($this->_table, $where,$offset,$num);
return $query->result_array();
}
而这种发放有局限性,因为where里面不能写很多东西,只能写查询的字段,但是如果加上了$this->db->like这种东西,参数会有7-9个
有没有一种方法参数传递的少,还能够很自由的传递参数
有人说重构query buider但是我不知道这个在哪里,怎么重构
谢谢了 |
|