汇总CodeIgniter(CI)的数据库操作函数
分类:PHP_Python| 发布:佚名| 查看:1852 | 发表时间:2014/8/15
网上倒是有不少Codeigniter数据库操作的介绍,这里做一个汇总。
代码如下:
002 | $query = $this ->db_query( "SELECT * FROM table" ); |
003 | ================================== |
006 | $data = $query ->result(); |
009 | $data = $query ->result_array(); |
012 | $data = $query ->row(); |
015 | $data = $query ->num_rows(); |
018 | $data = $query ->num_fields(); |
021 | $data = $query ->row_array(); |
024 | $data = $query ->free_result(); |
033 | echo $this ->db->insert_id(); |
036 | echo $this ->db->affected_rows(); |
039 | echo $this ->db->count_all( 'table_name' ); |
042 | echo $this ->db->version(); |
045 | echo $this ->db->platform(); |
048 | echo $this ->db->last_query(); |
052 | $this ->db->insert_string( 'table_name' , $data ); |
063 | $this ->db->update_string( 'table_name' , $data , $where ); |
072 | $this ->db->get( 'table_name' ); |
075 | $this ->db->get( 'table_name' , 10, 20); |
078 | $this ->db->get_where( 'table_name' , array ( 'id' => $id ), $offset ); |
081 | $this ->db->select( 'title, content, date' ); |
082 | $data = $this ->db->get( 'table_name' ); |
085 | $this ->db->select_max( 'age' ); |
086 | $this ->db->select_max( 'age' , 'nianling' ); |
089 | $this ->db->select_min( 'age' ); |
090 | $this ->db->select_min( 'age' , 'nianling' ); |
093 | $this ->db->select_sum( 'age' ); |
094 | $this ->db->select_sum( 'age' , 'nianling' ); |
097 | $this ->db->select( 'title' , content, date '); |
098 | $this ->db->from( 'table_name' ); |
101 | $this ->db->where( 'name' , $name ); |
102 | $this ->db->where( 'title' , $title ); |
103 | $this ->db->where( 'status' , $status ); |
106 | $this ->db->where_in( 'item1' , 'item2' ); |
107 | $this ->db->where_not_in( 'item1' , 'item2' ); |
110 | $this ->db->like( 'title' , 'match' , 'before/after/both' ); |