温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CI框架常用函数封装

发布时间:2021-09-03 14:10:59 来源:亿速云 阅读:111 作者:小新 栏目:开发技术

这篇文章主要为大家展示了“CI框架常用函数封装”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“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框架常用函数封装”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI