老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)

PHP7操作MongoDB的增刪改查和分頁操作


原文博客地址www.xiegaosheng.com/post/view?id=96;

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:主機(jī)域名虛擬主機(jī)、營銷軟件、網(wǎng)站建設(shè)、海晏網(wǎng)站維護(hù)、網(wǎng)站推廣。

mongodb = new MongoDB\Driver\Manager("mongodb://localhost:27017");
      $this->dbname = $config['dbname'];
      $this->collection = $config['collection'];
      $this->bulk = new MongoDB\Driver\BulkWrite();
      $this->writeConcern   = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 100);
   }

    /**
     * Created by PhpStorm.
     * function: query
     * Description:查詢方法
     * User: Xiaoxie
     * Email 736214763@qq.com
     * @param array $where
     * @param array $option
     * @return string
     *
     */
   public function query($where=[],$option=[])
   {
      $query = new MongoDB\Driver\Query($where,$option);
      $result = $this->mongodb->executeQuery("$this->dbname.$this->collection", $query);
      $data = [];
      if ($result) {
         # code...
         foreach ($result as $key => $value) {
            # code...
            array_push($data, $value);
         }
      }

      return json_encode($data);
   }

    /**
     * Created by PhpStorm.
     * function: getCount
     * Description:獲取統(tǒng)計(jì)數(shù)
     * User: Xiaoxie
     * Email 736214763@qq.com
     * @param array $where
     * @return int
     *
     */
   public function getCount($where=[])
   {
      $command = new MongoDB\Driver\Command(['count' => $this->collection,'query'=>$where]);
      $result = $this->mongodb->executeCommand($this->dbname,$command);
      $res = $result->toArray();
      $cnt = 0;
      if ($res) {
         # code...
         $cnt = $res[0]->n;
      }

      return $cnt;
   }

    /**
     * Created by PhpStorm.
     * function: page
     * Description:分頁數(shù)據(jù)
     * User: Xiaoxie
     * Email 736214763@qq.com
     * @param array $where
     * @param int $page
     * @param int $limit
     * @return string
     *
     */
   public function page($where=[],$page=1,$limit=10)
   {
      
      $count = $this->getCount($where);
      $data['count'] = $count;
      $endpage = ceil($count/$limit);
      if ($page>$endpage) {
         # code...
         $page = $endpage;
      }elseif ($page <1) {
         $page = 1;
      }
      $skip = ($page-1)*$limit;
      $options = [
         'skip'=>$skip,
          'limit'    => $limit
      ];
      $data['data'] = $this->query($where,$options);
      $data['page'] = $endpage;
      return json_encode($data);
   }

    /**
     * Created by PhpStorm.
     * function: update
     * Description:更新操作
     * User: Xiaoxie
     * Email 736214763@qq.com
     * @param array $where
     * @param array $update
     * @param bool $upsert
     * @return int|null
     *
     */
   public function update($where=[],$update=[],$upsert=false)
   {
      $this->bulk->update($where,['$set' => $update], ['multi' => true, 'upsert' => $upsert]);
      $result = $this->mongodb->executeBulkWrite("$this->dbname.$this->collection", $this->bulk, $this->writeConcern);
      return $result->getModifiedCount();
   }

    /**
     * Created by PhpStorm.
     * function: insert
     * Description:插入
     * User: Xiaoxie
     * Email 736214763@qq.com
     * @param array $data
     * @return mixed
     *
     */
   public function insert($data=[])
   {
      $result = $this->bulk->insert($data);
      return $result->getInsertedCount();
   }

    /**
     * Created by PhpStorm.
     * function: delete
     * Description:刪除
     * User: Xiaoxie
     * Email 736214763@qq.com
     * @param array $where
     * @param int $limit
     * @return mixed
     *
     */
   public function delete($where=[],$limit=1)
   {
      $result = $this->bulk->delete($where,['limit'=>$limit]);
      return $result->getDeletedCount();
   }
   
}
//實(shí)例化調(diào)用
$action = $_GET['action']?:exit('參數(shù)錯(cuò)誤');
$page = $_GET['page']?:1;
$where = json_decode($_GET['where'],true)?:[];
$limit = $_GET['limit']?:'10';
$data = json_decode($_GET['data'],true)?:[];
$option = json_decode($_GET['option'],true)?:[];
$collection = $_GET['collection'];
$mongodb = new MongodbClient(['dbname'=>$dbname,'collection'=>$collection]);

if ($action=='getCount') {
   # code...
   $data = $mongodb->getCount($where);
}elseif($action=='insert')
{
   $data = $mongodb->insert($data);
}
elseif($action=='update')
{
   $data = $mongodb->update($where,$data);
}
elseif($action=='delete')
{
   $data = $mongodb->delete($where);
}
elseif($action=='query')
{
   $data = $mongodb->query($where,$option);
}elseif($action=='page')
{
   $data = $mongodb->page($where,$page,$limit);
}

echo $data;

外部調(diào)用的時(shí)候只需 127.0.0.1/index.php?action=方法&where=等等參數(shù)就會返回json

網(wǎng)站題目:PHP7操作MongoDB的增刪改查和分頁操作
文章位置:http://www.xueling.net.cn/article/ispoid.html

其他資訊

在線咨詢
服務(wù)熱線
服務(wù)熱線:028-86922220
TOP
主站蜘蛛池模板: 亚洲伊人色综合网色欲WWW | 被黑人猛躁10次高潮视频 | 精品人伦一区二区三区蜜桃免费 | 亚洲色欲色欲色欲www | 亚洲精品尤物av在线观看任我爽 | 欧美人与牲口杂交在线播放免费 | 国产福利免费视频 | 亚洲日本香蕉视频 | 亚洲国产aⅴ精品一区二区 可以直接看的无码AV | w两个世界完整免费观看超清完整 | 国产激情999 | 六度影院鲁鲁片在线看 | 国产欧美性成人精品午夜 | 四虎海外影库www4hu | 无码少妇一区二区三区免费 | 中文字幕2018第一页 | 在线观看高清av | 久久国产精品成人无码网站 | 蜜臀va | 日本人又黄又爽又大又色 | 丰满人妻一区二区三区无码av | 国产欧美网址 | 777亚洲欧美日韩精品中文中字幕 | 日本毛片在线 | 亚洲精品TV久久久久久久久J | 欧美色交 | 精品国产乱码久久久久久影片 | www.久久网站 | 无码人妻一区二区三区免费视频 | 精品国产欧美日韩一区二区三区 | 国内自拍视频在线播放 | 久久久久欠精品国产毛片国产毛生 | 国产一区二区三区伦理 | voyeur精品偷窥 | 99久久精品无免国产免费 | FREEXXXXHD麻豆精品A∨ | 麻豆网站免费观看 | 亚洲精品小区久久久久久 | 成人深夜在线观看 | 国产午夜鲁丝片AV无码 | 亚洲精品v亚洲精品v日韩精品 |