加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

CodeIgniter学习笔记二:CI中的query_builder(AR)、连贯操作

发布时间:2020-05-25 03:29:35 所属栏目:PHP 来源:互联网
导读:一、开启query_builder在applicationconfigdatabase.php中添加如下代码(默认已开启):$query_builder = TRUE;二、查询数据//get$res = $this - db - get(test);$list = $res - result();var_dump($list);/*array (size=7)0 =object(stdClass)[18]public id

一、开启query_builder

在applicationconfigdatabase.php中添加如下代码(默认已开启):

= ;

二、查询数据

= -> db -> get('test' = ->( object(stdClass)[18] public 'id' => string '1' (length=1) public 'name' => string 'lu' (length=5) public 'title' => string 'ci learn' (length=8) 1 => object(stdClass)[19] public 'id' => string '2' (length=1) public 'name' => string 'jim' (length=3) public 'title' => string 'jim learn ci' (length=12)

三、插入数据

= 'name' => 'mary','title' => 'mary learn ci' = -> db -> insert('test', ( -> db -> -> db ->

四、更新数据

= 'name' => 'cilover','title' => 'cilover learn ci' = -> db -> update('test',,('id' => 1 ( -> db ->

五、删除数据

= -> db -> delete('test',('id'=>4 ( -> db ->

六、连贯操作

= -> db -> select('id,name'-> from('test'-> where('id >=',1-> limit(3,2) -> order_by('id desc'->( -> db ->= 1 ORDER BY `id` desc LIMIT 2,3

<span style="color: #008080;">var_dump(<span style="color: #800080;">$res -><span style="color: #000000;"> result());
<span style="color: #008000;">/<span style="color: #008000;">
array (size=3)
0 =>
object(stdClass)[17]
public 'id' => string '12' (length=2)
public 'name' => string 'mary' (length=4)
1 =>
object(stdClass)[16]
public 'id' => string '11' (length=2)
public 'name' => string 'mary' (length=4)
2 =>
object(stdClass)[28]
public 'id' => string '10' (length=2)
public 'name' => string 'mary' (length=4)
<span style="color: #008000;">
/

特别要注意limit是反的,where中的id与>=之前有空格。

七、where

-> db -> where('name','jim') -> get('test' -> db ->

<span style="color: #800080;">$this -> db -> where('name !=','jim') -> get('test'<span style="color: #000000;">);
<span style="color: #0000ff;">echo <span style="color: #800080;">$this -> db -><span style="color: #000000;"> last_query();
<span style="color: #008000;">//<span style="color: #008000;">SELECT * FROM ci_test WHERE name != 'jim'

<span style="color: #800080;">$this -> db -> where(<span style="color: #0000ff;">array('name' => 'jim','id >' => 2)) -> get('test'<span style="color: #000000;">);
<span style="color: #0000ff;">echo <span style="color: #800080;">$this -> db -><span style="color: #000000;"> last_query();
<span style="color: #008000;">//<span style="color: #008000;">SELECT * FROM ci_test WHERE name = 'jim' AND id > 2

更复杂的查询可以用query实现。

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读