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

自己實(shí)現(xiàn)的數(shù)據(jù)庫(kù)訪問(wèn)類

原創(chuàng) 2019-02-27 05:50:46 262
摘要:<?php namespace util; use think\Db; class SysDb {   //獲取表   public function table($table)   {     $this->where =&n
<?php
namespace util;
use think\Db;
class SysDb
{
  //獲取表
  public function table($table)
  {
    $this->where = '';
    $this->order = '';
    $this->limit = 0;
    $this->field = '*';
    $this->table = $table;
    return $this;
  }
  //獲取字段
  public function field($field='*')
  {
    $this->field = $field;
    return $this;
  }
  //獲取排序
  public function order($order='')
  {
    $this->order = $order;
    return $this;
  }
  //獲取數(shù)據(jù)條數(shù)
  public function limit($limit = '')
  {
    $this->limit = $limit;
    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->order && $query->order($this->order);
    $this->limit && $query->limit($this->limit);
    return $query->select();
  }
  //查詢指定索引
  public function cates($index)
  {
    $query = Db::name($this->table)->field($this->field)->where($this->where);
    $this->order && $query->order($this->order);
    $this->limit && $query->limit($this->limit);
    $res = $query->select();
    $data = [];
    foreach($res as $v){
      $data[$v[$index]] = $v;
    }
    return $data;
  }
  //查詢分頁(yè)數(shù)據(jù)
  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->order($this->order);
    $pageObj = $query->paginate($pageSize,$total);
    return ['total'=>$total,'data'=>$pageObj->items(),'pages'=>$pageObj->render()];
  }
}
 ?>


批改老師:查無(wú)此人批改時(shí)間:2019-02-27 09:07:10
老師總結(jié):完成的不錯(cuò)。where條件,最好多加點(diǎn)判斷,能剔除數(shù)據(jù)庫(kù)注入。繼續(xù)加油

發(fā)布手記

熱門(mén)詞條