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

SysDb的實(shí)現(xiàn)

Original 2019-06-04 16:45:05 267
abstract:通過SysDb類的封裝,把常用的增刪改查封裝到類中,去除了tp自帶的較為臃腫的方法庫。代碼如下:<?php namespace Util; use think\Db; class SysDb {     //設(shè)置查詢的業(yè)務(wù)表     public  func

通過SysDb類的封裝,把常用的增刪改查封裝到類中,去除了tp自帶的較為臃腫的方法庫。代碼如下:

<?php

namespace Util;

use think\Db;

class SysDb
{
    //設(shè)置查詢的業(yè)務(wù)表
    public  function  table($table)
    {
        $this->field='*';
        $this->where=[];
        $this->limit=0;
        $this->order='';

        $this->table=$table;
        return $this;
    }

    //字段
    public  function  field($field='*')
    {
        $this->field=$field;
        return $this;
    }

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

    //限制的條數(shù)
    public  function  limit($limit)
    {
        $this->limit=$limit;
        return $this;
    }

    //排序
    public  function  order($order='')
    {
        $this->order=$order;
        return $this;
    }

    //返回一條記錄
    public function  item()
    {
        $query=Db::name($this->table)->field($this->field)->where($this->where);

        if($this->order)
        {
            $query=$query->order($this->order);
        }

        return $query=$query->find();
    }

    //返回多條記錄
    public function lists()
    {
        $query=Db::name($this->table)->field($this->field)->where($this->where);

        if($this->limit)
        {
            $query=$query->order($this->limit);
        }

        if($this->order)
        {
            $query=$query->order($this->order);
        }

        return $query->select();
    }

    //返回指定條件的數(shù)據(jù)條數(shù)
    public  function  count()
    {
        return Db::name($this->table)->where($this->where)->count();
    }

    //分頁
    public function  pages($pageSize=10)
    {
        //數(shù)據(jù)總數(shù)
        $count=$this->count();

        $query=Db::name($this->table)->field($this->field)->where($this->where);

        if($this->order)
        {
            $query=$query->order($this->order);
        }

        //分頁數(shù)據(jù)
        $data=$query->paginate($pageSize,$count);

        return ['count'=>$count,'data'=>$data,'pages'=>$data->render()];
    }

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

    //批量添加數(shù)據(jù)
    public  function  insertAll($data)
    {
        return Db::name($this->table)->insertAll($data);
    }

    //更新
    public  function  update($data)
    {
        return Db::name($this->table)->where($this->where)->update($data);
    }

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


}


Correcting teacher:查無此人Correction time:2019-06-05 09:23:15
Teacher's summary:完成的不錯(cuò)。后臺(tái)cms管理系統(tǒng),就是對(duì)數(shù)據(jù)進(jìn)行操作。操作越簡單越好。繼續(xù)加油。

Release Notes

Popular Entries