CI框架常用函數(shù)封裝實(shí)例
本文實(shí)例講述了CI框架常用函數(shù)封裝。分享給大家供大家參考,具體如下:
/** * 封裝查詢函數(shù) */ public function get_what($table='',$where=array(),$fields = ' * '){ if( '' == $table ){ return false; } //查詢并返回相關(guān)結(jié)果 $query = $this->db->select($fields)->where($where)->get($table); $res = $query->result_array(); return $res; } /** * 封裝單條查詢函數(shù) */ public function get_row($table='',$where=array(),$fields = ' * '){ if( '' == $table ){ return false; } //查詢并返回相關(guān)結(jié)果 $query = $this->db->select($fields)->where($where)->get($table); $res = $query->row_array(); return $res; } /** * 封裝更新函數(shù) */ public function update_what($table='', $where=array(), $data = array()){ if('' == $table || true === empty($where) || true === empty($data)){ return false; } //更新相應(yīng)的字段 $query = $this->db->update($table,$data,$where); return $query; } /** * 擴(kuò)展數(shù)據(jù)庫(kù)函數(shù)之自增 自減 * using: * $table = 'codeuser'; $where = array('id'=>1); $data = array('usestate'=>'usestate+1','imgtype' => 'imgtype-1'); */ public function update_count($table = '', $where=array(), $data=array()){ //如果表名為空 或者數(shù)據(jù)為空則直接 返回false if('' == $table || empty($data)){ return false; } foreach($data as $key => $val){ if(false !== stripos($val,'+') || false !== stripos($val,'-')){ $this->db->set($key, $val, FALSE); }else{ $this->db->set($key, $val); } } $res = $this->db->where($where)->update($table); return $res; } /** * 封裝插入函數(shù) */ public function insert_what($table = '', $data = array()){ if('' == $table || true === empty($data)){ return false; } //插入 相關(guān)記錄 $query = $this->db->insert($table, $data); return $query; } /** * 刪除記錄封裝函數(shù) */ public function delete_what($table = '', $where=array()){ if(true === empty($where) || '' == $table){ return false; } //刪除相關(guān)表記錄 $query = $this->db->delete($table,$where); return $query; } /** * debug 相關(guān)函數(shù) */ public function debug_what($org_error = ''){ $con = $this->router->fetch_class(); $func = $this->router->fetch_method(); if($org_error){ $error .= date("Y-m-d H:i:s",time())."\r\n"; $error .= __FILE__."\r\n"; $error .= $con." 控制器下的:\r\n"; $error .= $func." 方法調(diào)試信息如下:\r\n"; $error .= $org_error;file_put_contents("./error_log.txt",$error."\r\n",FILE_APPEND); } }
更多關(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è)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家基于CodeIgniter框架的PHP程序設(shè)計(jì)有所幫助。
- CI框架AR數(shù)據(jù)庫(kù)操作常用函數(shù)總結(jié)
- CI框架源碼解讀之URI.php中_fetch_uri_string()函數(shù)用法分析
- CI框架中數(shù)據(jù)庫(kù)操作函數(shù)$this->db->where()相關(guān)用法總結(jié)
- Laravel與CI框架中截取字符串函數(shù)
- CI框架驗(yàn)證碼CAPTCHA輔助函數(shù)用法實(shí)例
- Codeigniter(CI)框架分頁(yè)函數(shù)及相關(guān)知識(shí)
- CodeIgniter輔助函數(shù)helper詳解
- codeigniter數(shù)據(jù)庫(kù)操作函數(shù)匯總
相關(guān)文章
thinkphp 3.2框架視圖模型 實(shí)例視圖查詢結(jié)果的二維數(shù)組合并操作示例
這篇文章主要介紹了thinkphp 3.2框架視圖模型 實(shí)例視圖查詢結(jié)果的二維數(shù)組合并操作,結(jié)合實(shí)例形式分析了thinkPHP3.2針對(duì)視圖查詢結(jié)果的數(shù)組合并相關(guān)操作技巧,需要的朋友可以參考下2020-03-03php判斷手機(jī)瀏覽還是web瀏覽,并執(zhí)行相應(yīng)的動(dòng)作簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇php判斷手機(jī)瀏覽還是web瀏覽,并執(zhí)行相應(yīng)的動(dòng)作簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給的大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2016-07-07PHP編寫學(xué)校網(wǎng)站上新生注冊(cè)登陸程序的實(shí)例分享
這篇文章主要介紹了使用PHP編寫學(xué)校網(wǎng)站上新生注冊(cè)登陸程序的實(shí)例分享,只包括簡(jiǎn)單的數(shù)據(jù)庫(kù)信息錄入和查詢等步驟的一些關(guān)鍵點(diǎn),需要的朋友可以參考下2016-03-03ThinkPHP框架設(shè)計(jì)及擴(kuò)展詳解
本文詳細(xì)介紹了ThinkPHP框架的框架分層及url路由、ThinkPHP擴(kuò)展、數(shù)據(jù)庫(kù)驅(qū)動(dòng)擴(kuò)展、Behavior行為擴(kuò)展以及源碼分析與不足,講解的十分全面系統(tǒng),這里推薦給大家,有想學(xué)習(xí)ThinkPHP的小伙伴千萬(wàn)不要錯(cuò)過。2014-11-11Laravel框架模板加載,分配變量及簡(jiǎn)單路由功能示例
這篇文章主要介紹了Laravel框架模板加載,分配變量及簡(jiǎn)單路由功能,結(jié)合實(shí)例形式分析了Laravel框架模板加載,分配變量及簡(jiǎn)單路由功能相關(guān)原理、操作技巧與注意事項(xiàng),需要的朋友可以參考下2018-06-06