CI框架常用函數(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ù)庫函數(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è)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于CodeIgniter框架的PHP程序設(shè)計有所幫助。
相關(guān)文章
PHP設(shè)計模式(五)適配器模式Adapter實例詳解【結(jié)構(gòu)型】
這篇文章主要介紹了PHP設(shè)計模式:適配器模式Adapter,結(jié)合實例形式詳細(xì)分析了PHP適配器模式Adapter基本概念、功能、原理、用法及操作注意事項,需要的朋友可以參考下2020-05-05
PHP的openssl加密擴(kuò)展使用小結(jié)(推薦)
下面小編就為大家?guī)硪黄狿HP的openssl加密擴(kuò)展使用小結(jié)(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-07-07
PHP使用Face++接口開發(fā)微信公眾平臺人臉識別系統(tǒng)的方法
這篇文章主要介紹了PHP使用Face++接口開發(fā)微信公眾平臺人臉識別系統(tǒng)的方法,涉及微信公眾平臺相關(guān)接口的使用技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04
Laravel+Layer實現(xiàn)圖片上傳功能(整理篇)
這篇文章主要介紹了Laravel+Layer實現(xiàn)圖片上傳功能(整理篇),需要的朋友可以參考下2018-01-01
PHP通過微信跳轉(zhuǎn)的Code參數(shù)獲取用戶的openid(關(guān)鍵代碼)
這篇文章主要介紹了PHP通過微信跳轉(zhuǎn)的Code參數(shù)獲取用戶的openid(關(guān)鍵代碼)的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-07-07

