• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

关于CI框架常用的函数封装

php 搞代码 3年前 (2022-01-22) 11次浏览 已收录 0个评论

这篇文章主要介绍了CI框架常用函数封装,结合实例形式分析了CI框架常用的数据库查询、插入、删除、更新及debug调试等操作技巧,需要的@本文来*源gaodai#ma#com搞*!代#%^码$网*朋友可以参考下

本文实例讲述了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())."\r\n";      $error .= __FILE__."\r\n";      $error .= $con." 控制器下的:\r\n";      $error .= $func." 方法调试信息如下:\r\n";      $error .= $org_error;file_put_contents("./error_log.txt",$error."\r\n",FILE_APPEND);    }}

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请随时关注我们网站!

相关推荐:

关于CI框架封装常用的图像处理方法

关于CI框架操作redis的方法

关于CI框架扩展系统核心类的方法分析

以上就是关于CI框架常用的函数封装的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:关于CI框架常用的函数封装

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址