a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁(yè) > 數(shù)據(jù)庫(kù) > MongoDB > 正文

php實(shí)現(xiàn)的mongodb操作類

2020-03-22 19:08:35
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
html' target='_blank'>public function __construct($host = NULL, $port = NULL, $dbname = NULL, $table = NULL) if (NULL === $dbname) { $this- throwError('集合不能為空!'); //判斷是否傳遞了host和port if (NULL !== $host) { $this- host = $host; if (NULL !== $port) { $this- port = $port; $this- table = $table; $this- mongo = new MongoClient($this- host . ':' . $this- port); if ($this- getVersion() = '0.9.0') { $this- dbname = $this- mongo- selectDB($dbname); $this- db = $this- dbname- selectCollection($table); } else { $this- db = $this- mongo- $dbname- $table; public function getVersion() return MongoClient::VERSION; * 單例模式 * @return Mongo|null //public static function getInstance($host=null, $port=null, $dbname=null, $table=null){ // if(!(self::$instanceof instanceof self)){ // self::$instanceof = new self($host, $port, $dbname, $table); // } // return self::$instanceof; * 插入一條數(shù)據(jù) * @param array $doc public function insert($doc = array()) if (empty($doc)) { $this- throwError('插入的數(shù)據(jù)不能為空!'); //保存數(shù)據(jù)信息 try { if (!$this- db- insert($doc)) { throw new MongoException('插入數(shù)據(jù)失敗'); } catch (MongoException $e) { $this- throwError($e- getMessage()); * 插入多條數(shù)據(jù)信息 * @param array $doc public function insertMulti($doc = array()) if (empty($doc)) { $this- throwError('插入的數(shù)據(jù)不能為空!'); //插入數(shù)據(jù)信息 foreach ($doc as $key = $val) { //判斷$val是不是數(shù)組 if (is_array($val)) { $this- insert($val); * 查找一條記錄 * @return array|null public function findOne($where = NULL) if (NULL === $where) { try { if ($result = $this- db- findOne()) { return $result; } else { throw new MongoException('查找數(shù)據(jù)失敗'); } catch (MongoException $e) { $this- throwError($e- getMessage()); } else { try { if ($result = $this- db- findOne($where)) { return $result; } else { throw new MongoException('查找數(shù)據(jù)失敗'); } catch (MongoException $e) { $this- throwError($e- getMessage()); * todo 帶條件的隨后做 * 查找所有的文檔 * @return MongoCursor public function find($where = NULL) if (NULL === $where) { try { if ($result = $this- db- find()) { } else { throw new MongoException('查找數(shù)據(jù)失敗'); } catch (MongoException $e) { $this- throwError($e- getMessage()); } else { try { if ($result = $this- db- find($where)) { } else { throw new MongoException('查找數(shù)據(jù)失敗'); } catch (MongoException $e) { $this- throwError($e- getMessage()); $arr = array(); foreach ($result as $id = $val) { $arr[] = $val; return $arr; * 獲取記錄條數(shù) * @return int public function getCount() try { if ($count = $this- db- count()) { return $count; } else { throw new MongoException('查找總數(shù)失敗'); } catch (MongoException $e) { $this- throwError($e- getMessage()); * 獲取所有的數(shù)據(jù)庫(kù) * @return array public function getDbs() return $this- mongo- listDBs(); * 刪除數(shù)據(jù)庫(kù) * @param null $dbname * @return mixed public function dropDb($dbname = NULL) if (NULL !== $dbname) { $retult = $this- mongo- dropDB($dbname); if ($retult['ok']) { return TRUE; } else { return FALSE; $this- throwError('請(qǐng)輸入要?jiǎng)h除的數(shù)據(jù)庫(kù)名稱'); * 強(qiáng)制關(guān)閉數(shù)據(jù)庫(kù)的鏈接 public function closeDb() $this- mongo- close(TRUE); * 輸出錯(cuò)誤信息 * @param $errorInfo 錯(cuò)誤內(nèi)容 public function throwError($errorInfo='') echo " h3 出錯(cuò)了:$errorInfo /h3 die();以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。PHP教程

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 在线观看国产小视频 | 三级电影网址 | 欧美性久久 | 欧美成人精品 | 亚洲免费网 | 污网址在线观看 | 日本精品区 | 播放一区 | 国产精品久久久久9999赢消 | 日韩视频欧美视频 | 黄色毛片一级 | 久久综合热| 久久精品免费 | 午夜精品久久久久久久久久蜜桃 | 你懂的在线视频播放 | 国产偷v国产偷∨精品视频 国产偷v国产偷v亚洲 | 欧美资源在线 | 成人一区在线观看 | 亚洲欧美一区二区三区在线 | 国产精品久久久久久婷婷天堂 | 一级毛片中国 | 久草天堂| 久久午夜精品 | 久久免费视频国产 | 天天天天爽 | 成人一区二区三区视频 | 国产午夜精品一区二区三区 | 蜜桃av一区二区三区 | 精品国产高清一区二区三区 | 99久久精品国产一区二区三区 | 国产伦精品一区二区三区视频网站 | 成人不卡在线 | 久久人人爽人人爽人人片av不 | 99久久婷婷国产精品综合 | 成人av福利 | 一区二区av在线 | 激情欧美一区二区三区中文字幕 | 久久久久久一区 | 成人av片在线观看 | 亚洲视频在线观看免费 | 亚洲视频免费网站 |