手机
当前位置:查字典教程网 >编程开发 >php教程 >CI框架常用函数封装实例
CI框架常用函数封装实例
摘要:本文实例讲述了CI框架常用函数封装。分享给大家供大家参考,具体如下:/***封装查询函数*/publicfunctionget_what($...

本文实例讲述了CI框架常用函数封装。分享给大家供大家参考,具体如下:

/** * 封装查询函数 */ public function get_what($table='',$where=array(),$fields = ' * '){ if( '' == $table ){ return false; } //查询并返回相关结果 $query = $this->db->select($fields)->where($where)->get($table); $res = $query->result_array(); return $res; } /** * 封装单条查询函数 */ public function get_row($table='',$where=array(),$fields = ' * '){ if( '' == $table ){ return false; } //查询并返回相关结果 $query = $this->db->select($fields)->where($where)->get($table); $res = $query->row_array(); return $res; } /** * 封装更新函数 */ public function update_what($table='', $where=array(), $data = array()){ if('' == $table || true === empty($where) || true === empty($data)){ return false; } //更新相应的字段 $query = $this->db->update($table,$data,$where); return $query; } /** * 扩展数据库函数之自增 自减 * using: * $table = 'codeuser'; $where = array('id'=>1); $data = array('usestate'=>'usestate+1','imgtype' => 'imgtype-1'); */ public function update_count($table = '', $where=array(), $data=array()){ //如果表名为空 或者数据为空则直接 返回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; } /** * 封装插入函数 */ public function insert_what($table = '', $data = array()){ if('' == $table || true === empty($data)){ return false; } //插入 相关记录 $query = $this->db->insert($table, $data); return $query; } /** * 删除记录封装函数 */ public function delete_what($table = '', $where=array()){ if(true === empty($where) || '' == $table){ return false; } //删除相关表记录 $query = $this->db->delete($table,$where); return $query; } /** * debug 相关函数 */ 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())."rn"; $error .= __FILE__."rn"; $error .= $con." 控制器下的:rn"; $error .= $func." 方法调试信息如下:rn"; $error .= $org_error;file_put_contents("./error_log.txt",$error."rn",FILE_APPEND); } }

希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。

【CI框架常用函数封装实例】相关文章:

PHP中4种常用的抓取网络数据方法

php计算给定时间之前的函数用法实例

php注入实例

php简单smarty入门程序实例

PHP嵌套输出缓冲代码实例

php显示时间常用方法小结

php中smarty模板条件判断用法实例

PHP中的魔术方法总结和使用实例

PHP中的事务使用实例

用函数读出数据表内容放入二维数组

精品推荐
分类导航