本文整理汇总了PHP中Mongo::listDBs方法的典型用法代码示例。如果您正苦于以下问题:PHP Mongo::listDBs方法的具体用法?PHP Mongo::listDBs怎么用?PHP Mongo::listDBs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mongo
的用法示例。
在下文中一共展示了Mongo::listDBs方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hasDB
/**
* @param string $databaseName
* @return bool
*/
public static function hasDB($databaseName)
{
$databases = static::$_mongo->listDBs();
$result = array_filter($databases['databases'], function ($item) use($databaseName) {
return $item['name'] == $databaseName;
});
return count($result) != 0;
}
示例2: listDatabases
/**
* Returns a list of databases.
*
* @param boolean $detailed return detailed information
*
* @return array array containing database name or info arrays
*/
public function listDatabases($detailed = false)
{
$result = $this->connection->listDBs();
if ($detailed) {
return $result;
}
return array_map(function ($database) {
return $database['name'];
}, $result['databases']);
}
示例3: index
/**
* Show the application welcome screen to the user.
*
* @return Response
*/
public function index()
{
try {
$mongo = new Mongo();
//create a connection to MongoDB
$databases = $mongo->listDBs();
//List all databases
echo '<pre>';
print_r($databases);
$mongo->close();
} catch (MongoConnectionException $e) {
//handle connection error
die($e->getMessage());
}
return view('welcome');
}
示例4: listDbs
/**
* List databases on the server
*
* @return array
*/
public function listDbs()
{
$dbs = $this->_mongo->listDBs();
if (!$dbs["ok"]) {
$user = MUser::userInSession();
$dbs = array("databases" => array(), "totalSize" => 0, "ok" => 1);
foreach ($user->dbs() as $db) {
$dbs["databases"][] = array("name" => $db, "empty" => false, "sizeOnDisk" => 0);
}
}
//@todo: should we show user input databases only?
$onlyDbs = $this->uiOnlyDbs();
$hideDbs = $this->uiHideDbs();
foreach ($dbs["databases"] as $index => $database) {
$name = $database["name"];
if (!empty($hideDbs) && in_array($name, $hideDbs)) {
unset($dbs["databases"][$index]);
}
if (!empty($onlyDbs) && !in_array($name, $onlyDbs)) {
unset($dbs["databases"][$index]);
}
}
return $dbs;
}
示例5: Mongo
<?php
try {
$mongo = new Mongo($server = 'mongodb://localhost:27017/', $options = array('timeout' => 100));
//create a connection to MongoDB
$databases = $mongo->listDBs();
//List all databases;
echo '<pre>';
print_r($databases);
$mongo->close();
} catch (MongoConnectionException $e) {
die($e->getMessage());
}
示例6: listDatabases
/** @proxy */
public function listDatabases()
{
$this->initialize();
return $this->mongo->listDBs();
}
示例7: testListDBs
public function testListDBs() {
$m = new Mongo();
$dbs = $m->listDBs();
$this->assertEquals(true, (bool)$dbs['ok'], json_encode($dbs));
$this->assertTrue(array_key_exists('databases', $dbs));
}
示例8: createMongoDBConfig
protected function createMongoDBConfig($update_from_config_alt)
{
require_once "I2CE_MagicDataStorageMongoDB.php";
$db = MDB2::singleton();
if (!($db_name = $db->database_name)) {
I2CE::raiseError("No database to connect to MongoDB");
return false;
}
if (!($db_password = $db->dsn['password'])) {
I2CE::raiseError("No password to connect to MongoDB");
return false;
}
if (!($db_user = $db->dsn['username'])) {
I2CE::raiseError("No user to connect to MongoDB");
return false;
}
$conn_string = "mongodb://localhost";
try {
$m = new Mongo($conn_string);
} catch (Exception $e) {
I2CE::raiseError("Could not connect to mongodb using: " . $conn_string);
return false;
}
if (!is_array($dbs = $m->listDBs()) || !array_key_exists('databases', $dbs) || !is_array($dbs['databases'])) {
I2CE::raiseError("MongoDB: {$db_name} needs to be created");
//this is done automatically when we select below
} else {
$found = false;
foreach ($dbs['databases'] as $info) {
if (!is_array($info) || !array_key_exists('name', $info) || !($info['name'] = $db_name)) {
continue;
}
$found = true;
}
if (!$found) {
I2CE::raiseError("MongoDB: The database {$db_name} needs to be created:" . print_r($dbs, true));
}
}
$new_coll = false;
if (!($mdb = $m->selectDB($db_name)) instanceof MongoDB) {
I2CE::raiseError("Cannont connect to mongo database {$db_name}");
return false;
}
if (!is_array($mcolls = $mdb->listCollections()) || count($mcolls) == 0 || !in_array($db_name . ".config", $mcolls)) {
I2CE::raiseError("MongoDB: collection {$db_name}.config needs to be created");
//this is done automatically when we select below
$new_coll = true;
}
if (!($mcoll = $mdb->selectCollection('config')) instanceof MongoCollection) {
I2CE::raiseError("Cannot connect to config collection of mongo database {$db_name}");
return false;
}
if (!I2CE_MagicDataStorageMongoDB::setupIndices($mcoll)) {
I2CE::raiseError("Could not setup indices");
return false;
}
$qry = 'SHOW TABLES LIKE "config_alt"';
$result = $db->query($qry);
if (I2CE::pearError($result, "Cannot access database")) {
return false;
}
if ($result->numRows() < 1) {
$update_from_config_alt = false;
}
if ($update_from_config_alt && $new_coll) {
$qry_nodes = "SELECT IF( LENGTH(p.parent) > 1, concat(p.parent,'/',p.name),IF (LENGTH(p.name) > 1, CONCAT('/',p.name), '')) as path, p.value as value, p.type as type, \nGROUP_CONCAT(c.name SEPARATOR '/') AS children\nfrom config_alt AS p LEFT JOIN\n config_alt c \nON c.parent = IF( \n LENGTH(p.parent) > 1,\n concat(p.parent,'/',p.name),\n IF( LENGTH(p.name) > 1, CONCAT('/',p.name), CONCAT('/',p.name))\n) \nGROUP BY path";
$res = $db->query($qry_nodes);
if (PEAR::isError($res)) {
I2CE::raiseError("Could not query existing config_alt");
return false;
}
I2CE::raiseError("Populating mongodb from config_alt table");
while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
if ($row['type'] == '0') {
$children = preg_split('/\\//', $row['children'], -1, PREG_SPLIT_NO_EMPTY);
} else {
$children = null;
}
$data = array(I2CE_MagicDataStorageMongoDB::PATH => $row['path'], I2CE_MagicDataStorageMongoDB::TYPE => $row['type'], I2CE_MagicDataStorageMongoDB::VALUE => $row['value'], I2CE_MagicDataStorageMongoDB::CHILDREN => $children);
if (!is_array($r = $mcoll->insert($data, array("safe" => true))) || array_key_exists('err', $r) && $r['err']) {
I2CE::raiseError("Could not inset new node:" . print_r($r, true));
return false;
}
}
}
if (!$this->setupMagicDataStorage()) {
I2CE::raiseError("Could not setup magic data storage");
}
return true;
}
示例9: post
$dbname = post('dbname', 'test');
$ts = post('ts');
$op = post('op');
$ns = post('ns');
$millis = post('millis');
$sub = post('sub');
$options = post('options');
$co = post('co');
$html = '';
$collection = 'system.profile';
$haystack = array("{$dbname}.{$collection}", "{$dbname}.\$cmd", "{$dbname}.system.indexes", "{$dbname}.system.namespaces");
// 判断数据是否存在
$mongo = new Mongo('mongodb://' . $host);
//获取数据库列表
$select_dbstr = '<select name="dbname" id="dbname"><option value="">';
$dbases = $mongo->listDBs();
foreach ($dbases['databases'] as $dbs) {
$sdbname = $dbs['name'];
if ($sdbname == $dbname) {
$isselect = " selected ";
} else {
$isselect = "";
}
$select_dbstr .= '<option value="' . $sdbname . '" ' . $isselect . '>' . $sdbname . '</option>';
}
$select_dbstr .= '</select>';
if ($_POST['reset_profile']) {
$profile_size = intval($_POST['profile_size']) > 1000000 ? $_POST['profile_size'] : 1000000;
$mongo->{$dbname}->setProfilingLevel(0);
$mongo->{$dbname}->dropCollection($collection);
$mongo->{$dbname}->command(array("create" => $collection, "capped" => true, "size" => $profile_size));
示例10: foreach
}
?>
<h2>Databases</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Collections</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$dbs = $mongo->listDBs();
?>
<?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>
示例11: index
public function index()
{
$connection = new Mongo();
print_r($connection->listDBs());
//能打印出数据库数组,看看有几个数据库。
}