CI框架--数据库Query_Builder中的方法

时间:2022-11-30 09:04:23

  下面是DB_Query_Builder.php中,各个方法的声明:

选择字段(select)

public function select($select = '*', $escape = NULL)

  

求字段最大值和最小值(select_max,select_min)

public function select_max($select = '', $alias = '')
public function select_min($select = '', $alias = '')

  

求字段平均值、总和(select_avg,select_sum)

public function select_avg($select = '', $alias = '')
public function select_sum($select = '', $alias = '')

  

过滤重复记录的字段(distinct)

public function distinct($val = TRUE)

  

选择表(from、get)

public function from($from)   ->$from可以字符串,也可以是数组
public function get($table = '', $limit = NULL, $offset = NULL)

  

连接(join)

public function join($table, $cond, $type = '', $escape = NULL)

  

指定筛选条件(与)

  多个where()是使用and来连接条件的,如果要使用or连接条件的话,可以使用or_where。

public function where($key, $value = NULL, $escape = NULL)

  

指定筛选条件(或)

  多个or_where是使用or来连接多个条件。

public function or_where($key, $value = NULL, $escape = NULL)

  

指定条件范围(where_in)

public function where_in($key = NULL, $values = NULL, $escape = NULL)

  

模式匹配(like)

public function like($field, $match = '', $side = 'both', $escape = NULL)
public function not_like($field, $match = '', $side = 'both', $escape = NULL)
public function or_like($field, $match = '', $side = 'both', $escape = NULL)
public function or_not_like($field, $match = '', $side = 'both', $escape = NULL)

  

分组

public function group_by($by, $escape = NULL)

  

having条件(and)

public function having($key, $value = NULL, $escape = NULL)

  

or_having条件(or)

public function or_having($key, $value = NULL, $escape = NULL)

  

排序

public function order_by($orderby, $direction = '', $escape = NULL)

  

限制记录数

public function limit($value, $offset = 0)
public function offset($offset)

  

插入和删除

public function set($key, $value = '', $escape = NULL)
public function insert($table = '', $set = NULL, $escape = NULL)
public function update($table = '', $set = NULL, $where = NULL, $limit = NULL)