CI框架AR數(shù)據(jù)庫操作常用函數(shù)總結(jié)
本文實(shí)例講述了CI框架AR數(shù)據(jù)庫操作常用函數(shù)。分享給大家供大家參考,具體如下:
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(); //得到查詢結(jié)果 $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、結(jié)果結(jié)果集
result() //返回對象數(shù)組 result_array() //返回二維數(shù)組 row() //返回一個對象 row_array() //返回一維數(shù)組 num_rows() //返回查詢的行數(shù) num_fields() //返回查詢結(jié)果的字段數(shù) free_result() //釋放查詢所占的資源內(nèi)存
8、輔助查詢函數(shù)
$this->db->insert_id() //獲取剛剛插入的id
$this->db->affected_rows() //修改或插入影響的行數(shù)
$this->db->count_all(); //統(tǒng)計記錄的總條數(shù) 這一函數(shù)加入where條件無效
$this->db->last_query(); //最后一條執(zhí)行的sql語句
//注意以下兩個函數(shù)僅返回sql語句 不執(zhí)行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:關(guān)于CodeIgniter詳細(xì)使用技巧可參考本站在線手冊:
CodeIgniter 2.2.4用戶指南:
http://shouce.jb51.net/codeigniter2.2/
CodeIgniter 3.0用戶指南:
http://shouce.jb51.net/codeigniter3.0/
更多關(guān)于CodeIgniter相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《ThinkPHP入門教程》、《ThinkPHP常用方法總結(jié)》、《Zend FrameWork框架入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于CodeIgniter框架的PHP程序設(shè)計有所幫助。
- CodeIgniter框架數(shù)據(jù)庫事務(wù)處理的設(shè)計缺陷和解決方案
- codeigniter自帶數(shù)據(jù)庫類使用方法說明
- 讓CodeIgniter數(shù)據(jù)庫緩存自動過期的處理的方法
- 新浪SAE云平臺下使用codeigniter的數(shù)據(jù)庫配置
- codeigniter數(shù)據(jù)庫操作函數(shù)匯總
- Codeigniter操作數(shù)據(jù)庫表的優(yōu)化寫法總結(jié)
- CodeIgniter針對數(shù)據(jù)庫的連接、配置及使用方法
- CI框架(CodeIgniter)實(shí)現(xiàn)的數(shù)據(jù)庫增刪改查操作總結(jié)
- CI框架入門示例之?dāng)?shù)據(jù)庫取數(shù)據(jù)完整實(shí)現(xiàn)方法
- CodeIgniter框架數(shù)據(jù)庫基本操作示例
相關(guān)文章
PHP實(shí)現(xiàn)新型冠狀病毒疫情實(shí)時圖的實(shí)例
在本篇文章小編給大家分享一篇關(guān)于PHP新型冠狀病毒肺炎疫情實(shí)時圖源碼內(nèi)容,有興趣的朋友們可以本地測試下。2020-02-02
PHP使用第三方即時獲取物流動態(tài)實(shí)例詳解
這篇文章主要介紹了PHP使用第三方即時獲取物流動態(tài),非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-04-04
PHP讀取mssql json數(shù)據(jù)中文亂碼的解決辦法
PHP及網(wǎng)頁使用UTF-8編碼,數(shù)據(jù)庫是sql server2008,使用默認(rèn)編碼,當(dāng)讀取數(shù)據(jù)庫數(shù)據(jù)時,使用php自帶的json_encode()返回到前端,結(jié)果中文不顯示。下面腳本之家小編給大家介紹PHP讀取mssql json數(shù)據(jù)中文亂碼的解決辦法,需要的朋友一起學(xué)習(xí)2016-04-04
destoon實(shí)現(xiàn)調(diào)用熱門關(guān)鍵字的方法
這篇文章主要介紹了destoon實(shí)現(xiàn)調(diào)用熱門關(guān)鍵字的方法,對于進(jìn)行模板開發(fā)來說非常有用,需要的朋友可以參考下2014-07-07
淺析Yii2集成富文本編輯器redactor實(shí)例教程
yii2集成另外一個強(qiáng)大好用的富文本編輯器Redactor。接下來通過本文給大家介紹Yii2集成富文本編輯器redactor實(shí)例教程,感興趣的朋友一起學(xué)習(xí)吧2016-04-04
PHP中__LINE__,__FILE__,__DIR__等常用魔術(shù)常量實(shí)例講解
PHP?向它運(yùn)行的任何腳本提供了大量的預(yù)定義常量。魔術(shù)常量準(zhǔn)確來說并不能算是常量,常量我們在之前的文章中我們介紹到,常量被定義之后是不能被改變的。但是魔術(shù)常量是PHP預(yù)定義的一些常量,這些預(yù)定義的常量能夠因?yàn)樗谖恢玫淖兓兓?/div> 2022-12-12最新評論

