当前位置: 首页>>代码示例>>PHP>>正文


PHP Mongo::selectDb方法代码示例

本文整理汇总了PHP中Mongo::selectDb方法的典型用法代码示例。如果您正苦于以下问题:PHP Mongo::selectDb方法的具体用法?PHP Mongo::selectDb怎么用?PHP Mongo::selectDb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mongo的用法示例。


在下文中一共展示了Mongo::selectDb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: registerServices

 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices($di)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     $di['view']->setViewsDir(__DIR__ . '/views/');
     /**
      * The database connection is created based on the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname));
     };
     /**
      * The mongo connection is created
      */
     $di['mongo'] = function () {
         $mongo = new \Mongo();
         return $mongo->selectDb("biko");
     };
     /**
      * ODM Collection Manager
      */
     $di['collectionManager'] = function () {
         return new CollectionManager();
     };
     /**
      * Unique Cart ID generator
      */
     $di['unique'] = function () {
         return new Generator();
     };
 }
开发者ID:riquedesimone,项目名称:biko,代码行数:38,代码来源:Module.php

示例2: createConnection

 protected static function createConnection()
 {
     $server = isset($GLOBALS['mongo_server']) ? $GLOBALS['mongo_server'] : 'mongodb://localhost:27017';
     $dbName = isset($GLOBALS['mongo_db_name']) ? $GLOBALS['mongo_db_name'] : 'task_queue_tests';
     $mongo = new \Mongo($server);
     return $mongo->selectDb($dbName);
 }
开发者ID:rybakit,项目名称:taskqueue,代码行数:7,代码来源:MongoDBQueueTest.php

示例3: _connect

 /**
  * {@inheritdoc}
  */
 protected function _connect()
 {
     if (!$this->isConnected()) {
         $this->_connection = new \MongoClient($this->_hostString, $this->_config['options']);
         $this->_connection->connect();
         $this->_db = $this->_connection->selectDb($this->_config['options']['db']);
     }
 }
开发者ID:evaneos,项目名称:berthe,代码行数:11,代码来源:MongoDbAdapter.php

示例4: saveDataToMongo

 public function saveDataToMongo($data)
 {
     $connectTo = "{$this->host}:{$this->port}";
     $mongo = new Mongo($connectTo);
     $collection = $mongo->selectDb($this->database)->selectCollection($this->collection);
     foreach ($data as $k => $v) {
         if ($v) {
             $collection->insert((array) $v);
         }
     }
 }
开发者ID:roborovski,项目名称:nosql,代码行数:11,代码来源:jsonToMongo.php

示例5: auth

 public function auth($username, $password, $db = "admin")
 {
     if ($db === "") {
         if (!$this->_mongoAuth && $this->_mongoDb) {
             $db = $this->_mongoDb;
         } else {
             $db = "admin";
         }
     }
     $server = $this->_mongoHost . ":" . $this->_mongoPort;
     if (!$this->_mongoPort) {
         $server = $this->_mongoHost;
     }
     try {
         $this->_mongo = new Mongo($server, $this->_mongoOptions);
         $this->_mongo->setSlaveOkay(true);
     } catch (Exception $e) {
         echo "Unable to connect MongoDB, please check your configurations. MongoDB said:" . $e->getMessage() . ".";
         exit;
     }
     // changing timeout to the new value
     MongoCursor::$timeout = $this->_mongoTimeout;
     //auth by mongo
     if ($this->_mongoAuth) {
         $dbs = $db;
         if (!is_array($dbs)) {
             $dbs = preg_split("/\\s*,\\s*/", $dbs);
         }
         foreach ($dbs as $db) {
             $ret = $this->_mongo->selectDb($db)->authenticate($username, $password);
             if (!$ret["ok"]) {
                 return false;
             }
         }
     } else {
         if ($this->_controlAuth) {
             if (!isset($this->_controlUsers[$username]) || $this->_controlUsers[$username] != $password) {
                 return false;
             }
             //authenticate
             if (!empty($this->_mongoUser)) {
                 return $this->_mongo->selectDB($db)->authenticate($this->_mongoUser, $this->_mongoPass);
             }
         } else {
             //authenticate
             if (!empty($this->_mongoUser)) {
                 return $this->_mongo->selectDB($db)->authenticate($this->_mongoUser, $this->_mongoPass);
             }
         }
     }
     return true;
 }
开发者ID:tolsasha,项目名称:Forum_PO,代码行数:52,代码来源:MServer.php

示例6: getDataFromMongo

 public function getDataFromMongo()
 {
     $connectTo = "{$this->from_host}:{$this->from_port}";
     try {
         $mongo = new Mongo($connectTo);
         $collection = $mongo->selectDb($this->from_database)->selectCollection($this->from_collection);
     } catch (Exception $e) {
         die("Nie mogę nazwiązać połączenia z bazą mongo ({$connectTo} - db:{$this->from_database}, col: {$this->from_collection}) ");
     }
     // find everything in the collection
     $cursor = $collection->find();
     $array_out = array();
     foreach ($cursor as $obj) {
         $array_out[] = $obj;
     }
     return $array_out;
 }
开发者ID:roborovski,项目名称:nosql,代码行数:17,代码来源:mongoToCouch.php

示例7: registerServices

 /**
  * Registers the module-only services
  *
  * @param \Phalcon\DiInterface $di
  */
 public function registerServices($di)
 {
     /**
      * Read application wide and module only configurations
      */
     $appConfig = $di->get('config');
     $moduleConfig = (include __DIR__ . '/config/config.php');
     $di->set('moduleConfig', $moduleConfig);
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di->set('url', function () use($appConfig) {
         $url = new UrlResolver();
         $url->setBaseUri($appConfig->application->baseUri);
         return $url;
     });
     /**
      * Module specific dispatcher
      */
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($di->getShared('eventsManager'));
         $dispatcher->setDefaultNamespace('App\\Modules\\Frontend\\');
         return $dispatcher;
     });
     $di->setShared('request', function () use($appConfig) {
         return new \Phalcon\Http\Request();
     });
     /**
      * Include config per environment
      */
     include __DIR__ . '/config/config_' . $appConfig->application->environment . '.php';
     $database = $di->getConfig()->application->site . $di->get('request')->getQuery("country_code");
     /**
      * Simple database connection to localhost
      */
     $di->setShared('mongo', function ($config, $database) {
         $mongo = new \Mongo();
         return $mongo->selectDb($config->{$database}->dbname);
     }, true);
     $di->setShared('collectionManager', function () {
         return new \Phalcon\Mvc\Collection\Manager();
     }, true);
 }
开发者ID:sarahsampan,项目名称:compare-api,代码行数:49,代码来源:Module.php

示例8: auth

 public function auth($username, $password, $db = "admin")
 {
     if ($db === "") {
         if (!$this->_mongoAuth && $this->_mongoDb) {
             $db = $this->_mongoDb;
         } else {
             $db = "admin";
         }
     }
     $this->_mongo = new Mongo($this->_mongoHost . ":" . $this->_mongoPort);
     //auth by mongo
     if ($this->_mongoAuth) {
         $dbs = $db;
         if (!is_array($dbs)) {
             $dbs = preg_split("/\\s*,\\s*/", $dbs);
         }
         foreach ($dbs as $db) {
             $ret = $this->_mongo->selectDb($db)->authenticate($username, $password);
             if (!$ret["ok"]) {
                 return false;
             }
         }
     } else {
         if ($this->_controlAuth) {
             if (!isset($this->_controlUsers[$username]) || $this->_controlUsers[$username] != $password) {
                 return false;
             }
             //authenticate
             if (!empty($this->_mongoUser)) {
                 return $this->_mongo->selectDB($db)->authenticate($this->_mongoUser, $this->_mongoPass);
             }
         } else {
             //authenticate
             if (!empty($this->_mongoUser)) {
                 return $this->_mongo->selectDB($db)->authenticate($this->_mongoUser, $this->_mongoPass);
             }
         }
     }
     return true;
 }
开发者ID:jango2015,项目名称:nette-mongodb-sandbox,代码行数:40,代码来源:MServer.php

示例9: Mongo

<?php

//Create and instance of Morph_Storage passing in the appropriate database
$mongo = new Mongo();
$storage = new Morph_Storage($mongo->selectDb('myDB'));
//Find a maximum of 10 users that has more than 15 posts, skipping the first 10
$query = new Morph_Query();
$query->limit(10)->skip(10)->property('numberOfPosts')->greaterThan(15);
$users = $storage->findByQuery(new User(), $query);
开发者ID:kulobone,项目名称:mongodb,代码行数:9,代码来源:LimitSkipQuerying.php

示例10: Mongo

<?php
//Initialise Morph_Storage passing in the appropriate database
$mongo = new Mongo();
Morph_Storage::init($mongo->selectDb('myDB'));;

//Find users with the userName = j.d.moss
$user = new User();
$query = new Morph_Query();
$query->property('userName')->equals('j.d.moss');
$users = $user->findByQuery($query);
开发者ID:rickyrobinett,项目名称:morph,代码行数:10,代码来源:BasicQuerying.php

示例11: getDefaultConnectionPeer

function getDefaultConnectionPeer()
{
    define('DB_NAME', 'links');
    $m = new Mongo();
    return new LinkPeer($m->selectDb(DB_NAME));
}
开发者ID:paul-matthews,项目名称:Mongo-Db-Example,代码行数:6,代码来源:functions.php

示例12: function

$di['assets'] = function () {
    $assets = new AssetsManager();
    $assets->addJs('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', false)->addJs('//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js', false);
    return $assets;
};
/**
 * Flash service with custom CSS classes
 */
$di['flash'] = function () {
    return new Flash(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
};
/**
 * Flash service with custom CSS classes
 */
$di['flashDirect'] = function () {
    return new FlashDirect(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
};
$di['session'] = function () {
    $session = new Session(array('uniqueId' => 'dasshy-'));
    $session->start();
    return $session;
};
// Simple database connection to localhost
$di['mongo'] = function () {
    $mongo = new Mongo();
    return $mongo->selectDb("stats");
};
//Collection manager
$di['collectionManager'] = function () {
    return new CollectionManager();
};
开发者ID:asha1412,项目名称:dasshy,代码行数:31,代码来源:services.php

示例13: testNestedArray

 public function testNestedArray()
 {
     $count = 1500;
     $mongo = new Mongo();
     $mongoDB = $mongo->selectDb('testdb');
     $mongoCollection = $mongoDB->selectCollection('testcollection');
     $values = array();
     for ($i = 0; $i < $count; $i++) {
         $values[] = new MongoId($i);
     }
     $mongoCursor = $mongoCollection->find(array('_id' => array('$in' => $values)));
     while ($mongoCursor->hasNext()) {
         $mongoCursor->getNext();
     }
 }
开发者ID:redmeadowman,项目名称:mongo-php-driver,代码行数:15,代码来源:RegressionTest1.php

示例14: foreach

      <?php 
    foreach ($dbs['databases'] as $db) {
        if ($db['name'] === 'local' || $db['name'] === 'admin') {
            continue;
        }
        ?>
        <tr>
          <td><a href="<?php 
        echo $_SERVER['PHP_SELF'] . '?db=' . $db['name'];
        ?>
"><?php 
        echo $db['name'];
        ?>
</a></td>
          <td><?php 
        echo count($mongo->selectDb($db['name'])->listCollections());
        ?>
</td>

          <?php 
        if ($readOnly !== true) {
            ?>
            <td><a href="<?php 
            echo $_SERVER['PHP_SELF'];
            ?>
?delete_db=<?php 
            echo $db['name'];
            ?>
" onClick="return confirm('Are you sure you want to delete this database?');">Delete</a></td>
          <?php 
        } else {
开发者ID:platform-project,项目名称:platform-project,代码行数:31,代码来源:index.php

示例15: dirname

#!/usr/bin/env php
<?php 
require_once dirname(__FILE__) . '/Link.php';
require_once dirname(__FILE__) . '/LinkPeer.php';
define('DB_NAME', 'links');
$m = new Mongo();
$linkPeer = new LinkPeer($m->selectDb(DB_NAME));
// Ensure the db is empty
foreach ($linkPeer->fetchAll() as $link) {
    $linkPeer->delete($link);
}
// Print the contens of the database
echo "> initial database values:\n";
foreach ($linkPeer->fetchByTag('com') as $link) {
    echo "{$link}\n";
}
echo "\n----\n";
// Add some links
$lnk1 = new Link();
$lnk1->setUrl('http://www.google.com');
$lnk1->addTag('google');
$lnk1->addTag('com');
$lnk2 = new Link();
$lnk2->setUrl('http://www.mongodb.org');
$lnk2->addTag('mongodb');
$lnk2->addTag('org');
$lnk3 = new Link();
$lnk3->setUrl('http://www.ibuildings.com');
$lnk3->addTag('ibuildings');
$lnk3->addTag('com');
$lnk4 = new Link();
开发者ID:paul-matthews,项目名称:Mongo-Db-Example,代码行数:31,代码来源:run.php


注:本文中的Mongo::selectDb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。