麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 數據庫 > MongoDB > 正文

php實現的mongodb操作類

2020-03-22 19:08:35
字體:
來源:轉載
供稿:網友
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; * 插入一條數據 * @param array $doc public function insert($doc = array()) if (empty($doc)) { $this- throwError('插入的數據不能為空!'); //保存數據信息 try { if (!$this- db- insert($doc)) { throw new MongoException('插入數據失敗'); } catch (MongoException $e) { $this- throwError($e- getMessage()); * 插入多條數據信息 * @param array $doc public function insertMulti($doc = array()) if (empty($doc)) { $this- throwError('插入的數據不能為空!'); //插入數據信息 foreach ($doc as $key = $val) { //判斷$val是不是數組 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('查找數據失敗'); } catch (MongoException $e) { $this- throwError($e- getMessage()); } else { try { if ($result = $this- db- findOne($where)) { return $result; } else { throw new MongoException('查找數據失敗'); } 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('查找數據失敗'); } catch (MongoException $e) { $this- throwError($e- getMessage()); } else { try { if ($result = $this- db- find($where)) { } else { throw new MongoException('查找數據失敗'); } catch (MongoException $e) { $this- throwError($e- getMessage()); $arr = array(); foreach ($result as $id = $val) { $arr[] = $val; return $arr; * 獲取記錄條數 * @return int public function getCount() try { if ($count = $this- db- count()) { return $count; } else { throw new MongoException('查找總數失敗'); } catch (MongoException $e) { $this- throwError($e- getMessage()); * 獲取所有的數據庫 * @return array public function getDbs() return $this- mongo- listDBs(); * 刪除數據庫 * @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('請輸入要刪除的數據庫名稱'); * 強制關閉數據庫的鏈接 public function closeDb() $this- mongo- close(TRUE); * 輸出錯誤信息 * @param $errorInfo 錯誤內容 public function throwError($errorInfo='') echo " h3 出錯了:$errorInfo /h3 die();以上所述就是本文的全部內容了,希望大家能夠喜歡。PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日韩黄网站 | 久久久久97国产精 | 黄色av片在线观看 | 99爱精品在线 | 操毛片 | 久久91久久久久麻豆精品 | 欧美成人国产va精品日本一级 | 久在线草| lutube成人福利在线观看污 | 国内精品国产三级国产a久久 | 视频一区二区三区视频 | 他也色在线视频 | 色婷婷久久一区二区 | 777zyz色资源站在线观看 | 日韩毛片免费观看 | 欧美性视频一区二区 | 欧美精品一区二区三区久久久 | 国产精品久久久久一区二区 | 黄色电影免费网址 | 日本xxxx色视频在线观看免费, | 九九热免费精品视频 | 主播粉嫩国产在线精品 | 88xx成人永久免费观看 | 成人在线视频免费看 | 中文字幕在线免费看 | 久久成人视屏 | 日韩中文字幕一区二区三区 | 久久久久久久久浪潮精品 | 黄网站色成年大片免费高 | 国产a级久久 | 亚洲精品无码不卡在线播放he | 国产精品欧美久久久久一区二区 | 中文字幕精品一二三四五六七八 | 黄色大片在线观看 | 麻豆蜜桃在线观看 | 91成人一区 | 免费a级黄色毛片 | fc2国产成人免费视频 | 久久久久北条麻妃免费看 | 国产亚洲精品久久久久久久久久 | 黄视频网址 |