當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Mongo::selectDB方法代碼示例

本文整理匯總了PHP中Mongo::selectDB方法的典型用法代碼示例。如果您正苦於以下問題:PHP Mongo::selectDB方法的具體用法?PHP Mongo::selectDB怎麽用?PHP Mongo::selectDB使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mongo的用法示例。


在下文中一共展示了Mongo::selectDB方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: connectMongo

 /**
  * @param string $databaseName
  * @return \MongoDB
  */
 private static function connectMongo($databaseName)
 {
     if (static::$_mongo == null) {
         static::$_mongo = new \Mongo();
     }
     return static::$_mongo->selectDB($databaseName);
 }
開發者ID:bbriggs,項目名稱:web-languageforge,代碼行數:11,代碼來源:MongoStore.php

示例2: initialize

 /**
  * Initialize the mongodb collection
  *
  * @throws \RuntimeException
  */
 public function initialize()
 {
     if (null !== $this->collection) {
         return;
     }
     if (empty($this->dbOptions['database'])) {
         throw new \RuntimeException('The option "database" must be set');
     }
     if (empty($this->dbOptions['collection'])) {
         throw new \RuntimeException('The option "collection" must be set');
     }
     $this->collection = $this->mongo->selectDB($this->dbOptions['database'])->selectCollection($this->dbOptions['collection']);
 }
開發者ID:msojda,項目名稱:KeyValueStore,代碼行數:18,代碼來源:MongoDbStorage.php

示例3: __construct

 /**
  * @return void
  */
 public function __construct($options)
 {
     if (!extension_loaded('mongo') && !extension_loaded('mongodb')) {
         \Zend_Cache::throwException('The MongoDB extension must be loaded for using this backend !');
     }
     parent::__construct($options);
     // Merge the options passed in; overridding any default options
     $this->_options = array_merge($this->_options, $options);
     $this->_conn = new \MongoClient('mongodb://' . $this->_options['host'] . ':' . $this->_options['port'], $this->_options['optional']);
     $this->_db = $this->_conn->selectDB($this->_options['dbname']);
     $this->_collection = $this->_db->selectCollection($this->_options['collection']);
     $this->_collection->ensureIndex(['t' => 1], ['background' => true]);
     $this->_collection->ensureIndex(['expire' => 1], ['background' => true]);
 }
開發者ID:solverat,項目名稱:pimcore,代碼行數:17,代碼來源:Mongodb.php

示例4: Mongo

 function __construct($db = null, $host = null)
 {
     $mongo = new Mongo($host);
     $database = $mongo->selectDB($db);
     $this->mongo = $mongo;
     $this->database = $database;
 }
開發者ID:XiaoFeiFeng,項目名稱:demo,代碼行數:7,代碼來源:DB.Mongo.php

示例5: __construct

 /**
  * $dsn has to contain db_name after the host. E.g. "mongodb://localhost:27017/mongo_test_db"
  *
  * @static
  * @param $dsn
  * @param $user
  * @param $password
  * @return \Mongo
  * @throws \Exception
  */
 public function __construct($dsn, $user, $password)
 {
     /* defining DB name */
     $this->dbName = substr($dsn, strrpos($dsn, '/') + 1);
     if (strlen($this->dbName) == 0) {
         throw new \Exception('Please specify valid $dsn with DB name after the host:port');
     }
     /* defining host */
     if (false !== strpos($dsn, 'mongodb://')) {
         $this->host = str_replace('mongodb://', '', $dsn);
     } else {
         $this->host = $dsn;
     }
     $this->host = rtrim(str_replace($this->dbName, '', $this->host), '/');
     $options = array('connect' => TRUE);
     if ($user && $password) {
         $options += array('username' => $user, 'password' => $password);
     }
     try {
         $m = new \Mongo($dsn, $options);
         $this->dbh = $m->selectDB($this->dbName);
     } catch (\MongoConnectionException $e) {
         throw new \Exception(sprintf('Failed to open Mongo connection: %s', $e->getMessage()));
     }
     $this->dsn = $dsn;
     $this->user = $user;
     $this->password = $password;
 }
開發者ID:lenninsanchez,項目名稱:donadores,代碼行數:38,代碼來源:MongoDb.php

示例6: getCollection

 /**
  * Return a "MongoCollection" instance
  *
  * @return \MongoCollection
  */
 private function getCollection()
 {
     if (null === $this->collection) {
         $this->collection = $this->mongo->selectDB($this->options['database'])->selectCollection($this->options['collection']);
     }
     return $this->collection;
 }
開發者ID:421p,項目名稱:symfony,代碼行數:12,代碼來源:MongoDbSessionHandler.php

示例7: conn

 protected function conn()
 {
     if (!isset(self::$_db_handle[$this->db_config_name])) {
         if (false == ($iconfig = C($this->db_config_name, 'db'))) {
             show_error('數據庫配製文件db.config.php中 ' . $this->db_config_name . '  未設置。');
         }
         $DSN = 'mongodb://';
         // exp: mongodb://192.168.1.222
         if ($iconfig['user']) {
             $DSN .= $iconfig['user'];
         }
         if ($iconfig['password']) {
             $DSN .= ':' . $iconfig['password'];
         }
         if ($DSN != 'mongodb://') {
             $DSN .= '@';
         }
         if ($iconfig['host']) {
             $DSN .= $iconfig['host'];
         }
         if (!empty($iconfig['port'])) {
             $DSN .= ':' . $iconfig['port'];
         }
         $mongoDB = new Mongo($DSN);
         self::$_db_handle[$this->db_config_name] = $this->db = $mongoDB->selectDB($iconfig['dbname']);
     } else {
         $this->db = self::$_db_handle[$this->db_config_name];
     }
     return $this->db;
 }
開發者ID:wangxian,項目名稱:ePHP,代碼行數:30,代碼來源:modelMongodb.class.php

示例8:

 /**
  * 構造查詢
  *
  * @param Mongo $mongo MongoDB連接
  * @param string $db 數據庫
  * @param string $collection 集合
  */
 function __construct(Mongo $mongo, $db, $collection)
 {
     $this->_dbName = $db;
     $this->_collectionName = $collection;
     $this->_db = $mongo->selectDB($this->_dbName);
     $this->_collection = $mongo->selectCollection($this->_dbName, $this->_collectionName);
 }
開發者ID:jango2015,項目名稱:nette-mongodb-sandbox,代碼行數:14,代碼來源:RQuery.php

示例9: Conf

 function __construct()
 {
     $this->conf = new Conf();
     $m = new Mongo();
     $db = $m->selectDB($this->conf->db());
     $this->selfColl = $db->zone;
 }
開發者ID:rebe100x,項目名稱:YAKREP,代碼行數:7,代碼來源:zone.php

示例10: createInstance

 /**
  * Creates a mongo connection and connects.
  *
  * @throws MongoConnectionException, Exception
  * @return MongoDB database object
  */
 private function createInstance()
 {
     //Pull these from a config file
     jimport('sml.smlconfig');
     $conf = new SMLConfig();
     $serverList = $conf->mongo_hosts;
     $database = $conf->mongo_db;
     $persistent = $conf->mongo_persistent;
     $paired = $conf->mongo_paired;
     //End config entries
     if (count($serverList) > 2) {
         throw new Exception("Connection can be established to 2 or fewer instances only.");
     }
     if (count($serverList) == 2) {
         $paired = true;
         $servers = implode(',', $serverList);
     } else {
         $servers = $serverList[0];
     }
     try {
         $m = new Mongo($servers, true, $persistent, $paired);
         $db = $m->selectDB($database);
     } catch (Exception $e) {
         //we should swallow this, and likely put a site down message up..
         die('<pre>' . $e->getTraceAsString());
     }
     return $db;
 }
開發者ID:spacemonkey,項目名稱:sml4joomla,代碼行數:34,代碼來源:jmongo.php

示例11: add_point

 public static function add_point($lat, $lon, $point_name)
 {
     $m = new Mongo();
     $db = $m->selectDB("your_db");
     $collection = $db->your_collection;
     $collection->insert(array("point_name" => $point_name, "loc" => array("lon" => $lon, "lat" => $lat)));
 }
開發者ID:ew-evidence-backup,項目名稱:php_boilerplate,代碼行數:7,代碼來源:MongoDB_GEO.php

示例12: __construct

 public function __construct()
 {
     $mongo = new Mongo();
     $mongoDb = $mongo->selectDB('ContactsManager');
     $this->contactsManagerCollection = new MongoCollection($mongoDb, 'Contact');
     $this->contactsManagerCollection->ensureIndex(array('email' => 1), array('unique' => true, 'dropDups' => true));
 }
開發者ID:lga37,項目名稱:contacts,代碼行數:7,代碼來源:ContactMongoStorage.php

示例13: __construct

 private function __construct()
 {
     $con = new Mongo("mongodb://" . MONGO_HOST . ":27017");
     $db = $con->selectDB(MONGO_DATABASE);
     // Connect to Database
     $this->mGrid = $db->getGridFS();
 }
開發者ID:programster,項目名稱:php-fms-test,代碼行數:7,代碼來源:ConnectionHandler.php

示例14: Conf

 function __construct()
 {
     $this->conf = new Conf();
     $m = new Mongo();
     $db = $m->selectDB($this->conf->db());
     $this->placeColl = $db->place;
     $this->yakCatColl = $db->yakcat;
     $this->filesourceColl = $db->filesource;
     $this->title = '';
     $this->content = '';
     $this->thumb = '';
     $this->origin = '';
     $this->filesourceId = '';
     $this->filesourceTitle = '';
     $this->access = 1;
     $this->licence = '';
     $this->outGoingLink = '';
     $this->yakTag = array();
     $this->yakCat = array();
     $this->humanCat = array();
     $this->freeTag = array();
     $this->creationDate = time();
     $this->lastModifDate = time();
     $this->location = new Location();
     $this->address = new Address();
     $this->formatted_address = "";
     $this->contact = new Contact();
     $this->status = 0;
     $this->user = 0;
     $this->zone = 0;
 }
開發者ID:rebe100x,項目名稱:YAKREP,代碼行數:31,代碼來源:place.php

示例15: _UpdateReport

 private static function _UpdateReport($url, $reportName)
 {
     $_host = parse_url($url, PHP_URL_HOST);
     $_today = new MongoDate(strtotime('today'));
     $connected = false;
     while (!$connected) {
         try {
             $_mdb = new Mongo();
             $connected = true;
         } catch (MongoConnectionException $e) {
             //echo "\nMongoConnectionException: ".$e->getMessage();
             sleep(1);
         }
     }
     $_reports = $_mdb->selectDB("googleproxy")->reports;
     $_rowFilter = array('host' => $_host, 'date' => $_today);
     $success = false;
     while (!$success) {
         try {
             if (!$_reports->findOne($_rowFilter)) {
                 $_reports->insert(array_merge($_rowFilter, array(ReportType::CacheHitCount => array('count' => 0), ReportType::RequestCount => array('count' => 0))));
             }
             $success = true;
         } catch (MongoCursorException $e) {
             //echo "\nMongoCursorException: ".$e->getMessage();
             sleep(1);
         }
     }
     $_reports->ensureIndex(array('report' => 1, 'date' => 1), array('background' => true));
     $_update = array('$inc' => array($reportName . '.count' => 1));
     $_options['multiple'] = false;
     $_reports->update($_rowFilter, $_update, $_options);
 }
開發者ID:sergrin,項目名稱:crawlers-il,代碼行數:33,代碼來源:Reporting.php


注:本文中的Mongo::selectDB方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。