《PHP實戰:CI框架AR數據庫操作常用函數總結》要點:
本文介紹了PHP實戰:CI框架AR數據庫操作常用函數總結,希望對您有用。如果有疑問,可以聯系我們。
PHP編程本文實例講述了CI框架AR數據庫操作常用函數.分享給大家供大家參考,具體如下:
PHP編程1、查詢表記錄
PHP編程
$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();
PHP編程2、增加表記錄
PHP編程
$this->db->insert();
PHP編程3、更改表記錄
PHP編程
$this->db->set();
$this->db->update();
PHP編程4、刪除表記錄
PHP編程
$this->db->delete();
PHP編程5、清空表記錄
PHP編程
$this->db->empty_table();
$this->db->truncate();
PHP編程6、緩存部分
PHP編程
$this->db->start_cache()
$this->db->stop_cache()
$this->db->flush_cache()
PHP編程7、結果結果集
PHP編程
result() //返回對象數組
result_array() //返回二維數組
row() //返回一個對象
row_array() //返回一維數組
num_rows() //返回查詢的行數
num_fields() //返回查詢結果的字段數
free_result() //釋放查詢所占的資源內存
PHP編程8、輔助查詢函數
PHP編程
$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); //返回正確格式的更新字符串
PHP編程PS:關于CodeIgniter詳細使用技巧可參考本站在線手冊:
PHP編程CodeIgniter 2.2.4用戶指南:
http://shouce.jb51.net/codeigniter2.2/
PHP編程CodeIgniter 3.0用戶指南:
http://shouce.jb51.net/codeigniter3.0/
PHP編程更多關于CodeIgniter相關內容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《php優秀開發框架總結》、《ThinkPHP入門教程》、《ThinkPHP常用方法總結》、《Zend FrameWork框架入門教程》、《php面向對象程序設計入門教程》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
PHP編程希望本文所述對大家基于CodeIgniter框架的PHP程序設計有所幫助.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/2611.html