亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

對(duì)數(shù)據(jù)庫訪問類封裝SysDb

Original 2019-07-24 23:37:19 268
abstract:<?php /**  * Created by PhpStorm.  * User: 普通用戶  * Date: 2019/7/24  * Time: 21:22  */ namespace Util; use think\Db;
<?php
/**
 * Created by PhpStorm.
 * User: 普通用戶
 * Date: 2019/7/24
 * Time: 21:22
 */

namespace Util;
use think\Db;

class SysDb
{
//    訪問表名,初始化條件屬性
    public function table($table){
        $this->where=[];
        $this->field='*';
        $this->order='';
        $this->limit=0;
        $this->table=$table;
        return $this;
    }

//    查詢的字段默認(rèn)為所有
    public function field($field='*'){
        $this->field=$field;
        return $this;
    }

//    查詢記錄數(shù)量
    public function limit($limit){
        $this->limit=$limit;
        return $this;
    }

    //查詢結(jié)果排序
    public function order($order){
        $this->order=$order;
        return $this;
    }

//    查詢條件
    public function where($where=[]){
        $this->where=$where;
        return $this;
    }

//    查找一條記錄
    public function item(){
        return Db::name($this->table)->field($this->field)->where($this->where)->find();
    }

//    查找多條記錄
    public function lists(){
        $query=Db::name($this->table)->field($this->field)->where($this->where);
        $this->limit && $query = $query->limit($this->limit);
        $this->order && $query = $query->order($this->order);
        return $query->select();
    }

//    自定義索引
    public  function cates($index){
        $query=Db::name($this->table)->field($this->field)->where($this->where);
        $this->limit && $query = $query->limit($this->limit);
        $this->order && $query = $query->order($this->order);
        $lists=$query->select();

        if(!$lists){
            return $lists;
        }
        $result=[];
        foreach($lists as $key=>$value){
            $result[$value[$index]]=$value;
        }
        return $result;
    }

//    查詢結(jié)果總數(shù)
    public function count(){
        return Db::name($this->table)->where($this->where)->count();
    }

    //分頁
    public function pages($pageSize=10){
        $total=Db::name($this->table)->where($this->where)->count();
        $query=Db::name($this->table)->field($this->field)->where($this->where);
        $this->order && $query=$query->order($this->order);
        $data=$query->paginate($pageSize,$total);
        return array('total'=>$total,'lists'=>$data->items(),'pages'=>$data->render());
    }

//    添加記錄
    public function insert($data){
        return Db::name($this->table)->insertGetId($data);
    }

//    添加多條記錄
    public function insertAll($data){
        return Db::name($this->table)->insertAll($data);
    }

//    刪除操作
    public function delete(){
        return Db::name($this->table)->where($this->where)->delete();
    }

//    自減操作
    public function setDec($index,$value=1){
        $res=Db::name($this->table)->where($this->where)->setDec($index,$value);
        return $res;
    }
}


Correcting teacher:查無此人Correction time:2019-07-25 13:06:06
Teacher's summary:完成的不錯(cuò)。多看thinkphp的文檔,多練習(xí)功能,很快就能上手。繼續(xù)加油。

Release Notes

Popular Entries