本文整理汇总了PHP中MongoClient::selectDB方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoClient::selectDB方法的具体用法?PHP MongoClient::selectDB怎么用?PHP MongoClient::selectDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoClient
的用法示例。
在下文中一共展示了MongoClient::selectDB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConnection
function getConnection($cache = false)
{
static $first;
$conf = new \ActiveMongo2\Configuration(__DIR__ . "/tmp/mapper.php");
$conf->addModelPath(__DIR__ . '/docs')->development();
if (!empty($_SERVER["NAMESPACE"])) {
if (!$first) {
print "Using namespace {$_SERVER['NAMESPACE']}\n";
}
$conf->SetNamespace($_SERVER["NAMESPACE"]);
}
if (!$first) {
$mongo = new MongoClient();
$mongo->selectDB('activemongo2_tests')->drop();
$mongo->selectDB('activemongo2_tests_foobar')->drop();
$config = new ActiveMongo2\Configuration();
unlink($config->getLoader());
}
if (empty($_SERVER["NAMESPACE"])) {
$zconn = new \ActiveMongo2\Client(new MongoClient(), 'activemongo2_tests', __DIR__ . '/docs');
} else {
$zconn = new \ActiveMongo2\Connection($conf, new MongoClient(), 'activemongo2_tests');
}
$zconn->AddConnection('foobar', new MongoClient(), 'activemongo2_tests_foobar', 'zzzz');
if ($cache) {
$zconn->setCacheStorage(new \ActiveMongo2\Cache\Storage\Memory());
}
$first = true;
return $zconn;
}
示例2: getDefaultDatabase
/**
* Get default database
*
* @return \MongoDB
*/
public function getDefaultDatabase()
{
if (is_null($this->defaultDb)) {
$this->defaultDb = $this->client->selectDB($this->config['database_name']);
}
return $this->defaultDb;
}
示例3: getDatabase
/**
* Get the collection instance, for internal use. Only creates the MongoCollection
* when called upon.
* @return MongoDB
*/
public function getDatabase()
{
if (!$this->db instanceof \MongoDB) {
$this->db = $this->client->selectDB($this->options['db']);
}
return $this->db;
}
示例4: getDriver
public function getDriver()
{
if (!$this->_driver) {
if (!isset($this->_config['handler_config'])) {
throw new Exception("Cannot found config for Mongo Session Handler");
}
$cfg = $this->_config['handler_config'];
$cfg = isset($cfg['options']) ? $cfg['options'] : array("connect" => true);
if (class_exists('Mongo')) {
$this->_driver = new \Mongo($cfg['dsn'], $cfg['options']);
} else {
if (class_exists('MongoClient')) {
$this->_driver = new \MongoClient($cfg['dsn'], $cfg['options']);
}
}
if (isset($cfg['options']['db'])) {
$db = $this->_driver->selectDB($cfg['options']['db']);
} else {
$db = $this->_driver->selectDB('session');
}
$this->_collectionName = isset($cfg['collection']) ? $cfg['collection'] : 'session_data';
$this->_collection = $db->selectCollection($this->_collectionName);
}
return $this->_driver;
}
示例5: connect
public function connect()
{
if ($this->_connection) {
return;
}
$host = $this->_config['connection']['server'];
if (isset($this->_config['connection']['username']) && isset($this->_config['connection']['password'])) {
$host = $this->_config['connection']['username'] . ':' . $this->_config['connection']['password'] . '@' . $host;
}
if (strpos($host, 'mongodb://') !== 0) {
$host = 'mongodb://' . $host;
}
if (!isset($options)) {
$options = array();
}
$options['connect'] = FALSE;
$this->_connection = new MongoClient($host, $options);
try {
$this->_connection->connect();
} catch (MongoConnectionException $e) {
throw new Exception('Unable to connect to Mongo server at :hostnames', array(':hostnames' => $e->getMessage()));
}
if (!isset($this->_config['connection']['db'])) {
throw new Exception('No database specified in MangoDB Config');
}
$this->_db = $this->_connection->selectDB($this->_config['connection']['db']);
return $this->_connected = TRUE;
}
示例6: setConnection
/**
* This function Define and assign the database
*/
private function setConnection()
{
$cn = new \MongoClient();
if (env('DB_ENV', 'development') == 'development') {
$this->database = $cn->selectDB("dbDevEndaroo01");
} else {
$this->database = $cn->selectDB("dbProdEndaroo01");
}
}
示例7: setConnection
/**
* This function Define and assign the database
*/
private function setConnection()
{
$cn = new \MongoClient();
if (env('DB_ENV', 'development') == 'development') {
self::$database = $cn->selectDB("dbAbbaDev01");
} else {
self::$database = $cn->selectDB("dbAbbaProd01");
}
}
示例8: init
private static function init()
{
if (self::$db) {
return;
}
$config = Kohana::$config->load('database')->get('mongo');
self::$client = new MongoClient($config['host']);
self::$db = self::$client->selectDB($config['database']);
}
示例9: execute
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$client = new \MongoClient($this->getContainer()->getParameter('mongo_server'));
$oldDb = $client->selectDB("muchacuba_old");
$newDb = $client->selectDB("muchacuba");
$oldCollection = $oldDb->selectCollection('infosms_past_infos');
$newCollection = $newDb->selectCollection('mc_info_sms_infos');
$oldItems = $oldCollection->find();
foreach ($oldItems as $oldItem) {
// Ignore duplicated
if (in_array($oldItem['_id'], ['5560cfd83a264', '5559ee4fbcaf3'])) {
continue;
}
// Ignore topic "Resultados"
if (in_array('55573f7ad089b', $oldItem['topics'])) {
continue;
}
// Ignore topic "Liga francia"
if (in_array($oldItem['_id'], ['556c5de0adfdd', '5559f282f16dc'])) {
continue;
}
// Ignore topic "Champions"
if (in_array($oldItem['_id'], ['55704dbff31dc'])) {
continue;
}
$topics = [];
// "Pelota"
if (in_array('55704c96e0835', $oldItem['topics'])) {
$topics = ['55704c96e0835'];
}
// "Liga Española"
if (in_array('55573fae42e4d', $oldItem['topics'])) {
$topics = ['55573fae42e4d'];
}
// "Liga Alemana"
if (in_array($oldItem['_id'], ['556c5c08c7e26', '5560ccc7e787b', '5559f236c6c13'])) {
$topics[] = '55573fc0e4b4b';
}
// "Liga Italiana"
if (in_array($oldItem['_id'], ['556c954c65057', '55676cad50d25', '5560cdb6d08a1', '555cfb26917c6', '5559f09c70e23', '5557552d8589a', '55574326465c0', '556f181c80784'])) {
$topics[] = '55573fc0f5a5c';
}
// "Liga Inglesa"
if (in_array($oldItem['_id'], ['556c5e09b8baf', '556c5df285087', '55636d1e17c77', '555ce26d61c7f', '5559f1fb5e58d', '5557422b694b8', '55574326465c0', '557c34084bfde', '55817e04e863f', '5585724cb32b6', '558ab96b1b202'])) {
$topics[] = '55573fc0e4c3a';
}
// "Selecciones nacionales"
if (in_array('5557400e229c5', $oldItem['topics'])) {
$topics[] = '5557400e229c5';
}
if (!$topics) {
var_dump($oldItem['_id']);
die;
}
$newCollection->insert(['id' => $oldItem['_id'], 'body' => $oldItem['body'], 'topics' => $topics, 'created' => $oldItem['created']]);
}
}
示例10: __construct
/**
* @return void
*/
public function __construct($options)
{
if (!extension_loaded('mongo')) {
\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($this->getServerConnectionUrl());
$this->_db = $this->_conn->selectDB($this->_options['dbname']);
$this->_collection = $this->_db->selectCollection($this->_options['collection']);
$this->_collection->ensureIndex(array('t' => 1), array('background' => true));
$this->_collection->ensureIndex(array('expires_at' => 1), array('background' => true));
}
示例11: __construct
/**
* Implement configurations for MongoDB connection
*
* @param \Phalcon\Config $config
* @throws \MongoConnectionException
*/
public function __construct(\Phalcon\Config $config)
{
try {
if (!$this->db) {
// init client
$this->client = new \MongoClient($this->getConnectUri($config));
// select database
$this->db = $this->client->selectDB($config['dbname']);
}
// select collection
$this->setCollection();
} catch (\MongoConnectionException $e) {
throw new \MongoConnectionException($e->getMessage());
}
}
示例12: testConnections
public function testConnections()
{
$client = new MongoClient();
$db1 = $client->selectDB('activemongo2_tests');
$db2 = $client->selectDB('activemongo2_tests_foobar');
$cols1 = array_map(function ($a) {
return (string) $a;
}, $db1->listCollections());
$cols2 = array_map(function ($a) {
return (string) $a;
}, $db2->listCollections());
$this->doTest($cols1, $cols2);
$this->doTest($cols2, $cols1);
$this->assertTrue(in_array('activemongo2_tests_foobar.zzzz.user', $cols2));
}
示例13: selectDB
/**
* @see MongoClient#selectDB
*/
public function selectDB($name)
{
if (!empty($name)) {
$this->dbname = $name;
}
return parent::selectDB($this->dbname);
}
示例14: setupmongo
function setupmongo()
{
//sets up a mongo connection
$mongo = new MongoClient("mongodb://technicolor:testbed@localhost/backendtest");
$collection = $mongo->selectDB('backendtest')->selectCollection('user');
return $collection;
}
示例15: setDatabase
function setDatabase($di, $host, $db)
{
$di->set('api_db', function () use($host, $db) {
$mongo = new MongoClient($host);
return $mongo->selectDB($db);
}, true);
}