您好,登錄后才能下訂單哦!
本篇文章為大家展示了如何CI框架AR數(shù)據(jù)庫(kù)操作常用函數(shù),內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
1、查詢(xún)表記錄
$this->db->select(); //選擇查詢(xún)的字段 $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(); //得到查詢(xún)結(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() //返回對(duì)象數(shù)組 result_array() //返回二維數(shù)組 row() //返回一個(gè)對(duì)象 row_array() //返回一維數(shù)組 num_rows() //返回查詢(xún)的行數(shù) num_fields() //返回查詢(xún)結(jié)果的字段數(shù) free_result() //釋放查詢(xún)所占的資源內(nèi)存
8、輔助查詢(xún)函數(shù)
$this->db->insert_id() //獲取剛剛插入的id $this->db->affected_rows() //修改或插入影響的行數(shù) $this->db->count_all(); //統(tǒng)計(jì)記錄的總條數(shù) 這一函數(shù)加入where條件無(wú)效 $this->db->last_query(); //最后一條執(zhí)行的sql語(yǔ)句 //注意以下兩個(gè)函數(shù)僅返回sql語(yǔ)句 不執(zhí)行sql語(yǔ)句 $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ì)使用技巧可參考本站在線(xiàn)手冊(cè):
CodeIgniter 2.2.4用戶(hù)指南:
http://shouce.jb51.net/codeigniter2.2/
CodeIgniter 3.0用戶(hù)指南:
http://shouce.jb51.net/codeigniter3.0/
上述內(nèi)容就是如何CI框架AR數(shù)據(jù)庫(kù)操作常用函數(shù),你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。