本文整理汇总了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();
};
}
示例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);
}
示例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']);
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
示例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);
示例11: getDefaultConnectionPeer
function getDefaultConnectionPeer()
{
define('DB_NAME', 'links');
$m = new Mongo();
return new LinkPeer($m->selectDb(DB_NAME));
}
示例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();
};
示例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();
}
}
示例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 {
示例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();