国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > 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教程

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 保定市| 汉川市| 周宁县| 金乡县| 若尔盖县| 岑巩县| 固始县| 张家口市| 永康市| 海兴县| 六安市| 万安县| 蓬莱市| 嘉善县| 永年县| 岑巩县| 邓州市| 明星| 五莲县| 吉木乃县| 永仁县| 准格尔旗| 西乌珠穆沁旗| 通州区| 黑山县| 南充市| 吴江市| 龙江县| 新建县| 天津市| 宾川县| 巧家县| 商河县| 青河县| 绥宁县| 水富县| 吉隆县| 镇坪县| 城固县| 水城县| 萍乡市|