php实现的mongodb操作类_PHP
程序员文章站
2022-04-20 12:30:02
...
mongo_db.php
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; /
上一篇: 值得玩味儿的生活小笑段