本文实例讲述了CI框架AR数据库操作常用函数。分享给大家供大家参考,具体如下:
1、查询表记录
$this->db->select(); //选择查询的字段 $this->db->select_max(); $this->db->select_min(); $this->db->select_avg(); $this->db->select_sum(); $this->db->from(); //选择表名 $this->db->join(); $this->db->get(); //得到查询结果 $this->db->get_where(); $this->db->where(); $this->db->or_where(); $this->db->where_in(); $this->db->or_where_in(); $this->db->where_not_in(); $this->db->or_where_not_in(); $this->db->like(); $this->db->or_like(); $this->db->not_like(); $this->db->or_not_like(); $this->db->group_by(); $this->db->distinct(); $this->db->having(); $this->db->or_having(); $this->db->order_by(); $this->db->limit(); $this->db->count_all_results();
2、增加表记录
$this->db->insert();
3、更改表记录
$this->db->set(); $this->db->update();
4、删除表记录
$this->db->delete();
5、清空表记录
$this->db->empty_table(); $this->db->truncate();
6、缓存部分
$this->db->start_cache() $this->db->stop_cache() $this->db->flush_cache()
7、结果结果集
result() //返回对象数组 result_array() //返回二维数组 row() //返回一个对象 row_array() //返回一维数组 num_rows() //返回查询的行数 num_fields() //返回查询结果的字段数 free_result() //释放查询所占的资源内存
8、辅助查询函数
$this->db->insert_id() //获取刚刚插入的id $this->db->affected_rows() //修改或插入影响的行数 $this->db->count_all(); //统计记录的总条数 这一函数加入where条件无效 $this->db->last_query(); //最后一条执行的sql语句 //注意以下两个函数仅返回sql语句 不执行sql语句 $data = array('name' => $name, 'email' => $email, 'url' => $url); $str = $this->db->insert_string('table_name', $data); $data = array('name' => $name, 'email' => $email, 'url' => $url); $where = "author_id = 1 AND status = 'active'"; $str = $this->db->update_string('table_name', $data, $where); //返回正确格式的更新字符串
PS:关于CodeIgniter详细使用技巧可参考本站在线手册:
CodeIgniter 2.2.4用户指南:
http://shouce.jb51.net/codeigniter2.2/
CodeIgniter 3.0用户指南:
http://shouce.jb51.net/codeigniter3.0/
更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《Zend FrameWork框架入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 潘秀琼.1994-木兰从军【名将】【WAV+CUE】
- 纯音入心系列纯音乐《古筝系列-当流行乐遇到古筝》1CD[MP3][1.9GB]
- 纯音入心系列纯音乐《精选古筝名曲100首》1CD[MP3][388.7MB]
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]