当前位置: 首页>>代码示例>>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;未经允许,请勿转载。