ci框架中数据库对象的加载过程及使用方法

——————–写在2018-01-10,这又是一个比较沉重的话题,本是为了解脱另一个问题,有踏入新的泥潭—————–
首先,先掌握使用方式在去了解为什么会有这些个使用方法!!在实际的工作生活中,一定是你有了解决问题的能力体现了自己的价值,然后才会有时间去丰富自己羽翼,甚至再去夯实基础的,不可能任何东西一上来就能让你明白原理,拿出大把时间去学习了之后再去运用的,除了上学时候。
写在前面,难点<1> 预处理 <2> 转义–即关于sql注入问题
<1> 常规查询——$this->db->query(‘your sql statement’);
<2> 查询绑定—–最重要的好处是,所有的值都会被自动转义,生成安全的查询语句。如代码是这样的
$sql = "select * from my_table where filed1 = ? and field2 = ?";
$query = $this->query($sql,array(value1,value2));
很明显,查询语句中的问号会被替代,替代的过程中会被自动转义。
<3> this>db>get(mytable);selectlimit, this->db->get(‘my_table’, 10 , 20 );
<3> this>db>from();. this->db->select(‘field’); this>db>from(mytable); query = this>db>get();<4> this->db->select(‘field1’ , ‘field2’, ‘field3’); 设置查询字段
<5> this>db>selectmax();/ this->db->select_min(); 获取字段的max/min值,还可以为字段设置别名, this>db>selectmax(field,alias);alias. this->db->select_avg();/ this>db>selectsum();<6> this->db->join();放弃使用这种方法
<7> this>db>where();<7.1>key/value使 this->db->where(‘name’,’value’);多个条件时,多次调用,不太方便
<7.2> 自定义的key/value形式。你可以在第一个参数中自定义一些比较字符,如 this>db>where(id<, id);
this>db>where(name!=, name);
<7.3>关联数组方式,方便多个条件时使用。 this>db>where(array(key=>value,key2=>value2));<7.4> where = “name = ‘zhuxinlei’ and male = 1 and age = 28 or age = 27”;
this>db>where( where);
<8> this>db>orwhere();where使 this->db->where(‘name’,’zhuxinlei’);
this>db>orwhere(age,28);//produce:wherename=zhuxinleiorage=28<9> this->db->where_in();用于生成where in语句, id=array(1,2,3); thid->db->where_in('id', id);<10> this->db->where_not_in();
<11>关于like的使用,放弃,我现在基本不适用like
<12> this>db>groupby();<13> this->db->order_by();可以对多个字段排序
this>db>orderby(id,desc); this->db->order_by(‘sort’,’asc’);
<14> this>db>limit();<15> this->db->insert();简单插入 data=array(id=>,name=>zhuxinlei,age=>28); this->db->insert('my_table', data);<16> this->db->insert_batch();批量插入 data=array(array(id=>,name=>zhuxinlei,age=>28),array(id=>,name=>houmeina,age=>28)); this->db->insert_batch('my_table', data);<17> this->db>replace('my_table', data);<18> this->db->set();
—————-够了够了,先说这些吧,下面开始真正的学习之路———-
<1>$this->load->database(); 我们知道,在ci中是通过这种方式加载数据库对象。回头就可以使用$this->db->func();的方式调用里面的各种方法,那database()方法中经历了what??

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值