mirror of
https://github.com/vrana/adminer.git
synced 2025-08-12 17:44:07 +02:00
Mongo: Add helper method
This commit is contained in:
@@ -15,10 +15,14 @@ if (isset($_GET["mongo"])) {
|
|||||||
|
|
||||||
function connect($uri, $options) {
|
function connect($uri, $options) {
|
||||||
$this->_link = new \MongoDB\Driver\Manager($uri, $options);
|
$this->_link = new \MongoDB\Driver\Manager($uri, $options);
|
||||||
$this->executeCommand($options["db"], array('ping' => 1));
|
$this->executeDbCommand($options["db"], array('ping' => 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeCommand($db, $command) {
|
function executeCommand($command) {
|
||||||
|
return $this->executeDbCommand($this->_db_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function executeDbCommand($db, $command) {
|
||||||
try {
|
try {
|
||||||
return $this->_link->executeCommand($db, new \MongoDB\Driver\Command($command));
|
return $this->_link->executeCommand($db, new \MongoDB\Driver\Command($command));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -118,7 +122,7 @@ if (isset($_GET["mongo"])) {
|
|||||||
function get_databases($flush) {
|
function get_databases($flush) {
|
||||||
global $connection;
|
global $connection;
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach ($connection->executeCommand($connection->_db_name, array('listDatabases' => 1)) as $dbs) {
|
foreach ($connection->executeCommand(array('listDatabases' => 1)) as $dbs) {
|
||||||
foreach ($dbs->databases as $db) {
|
foreach ($dbs->databases as $db) {
|
||||||
$return[] = $db->name;
|
$return[] = $db->name;
|
||||||
}
|
}
|
||||||
@@ -134,7 +138,7 @@ if (isset($_GET["mongo"])) {
|
|||||||
function tables_list() {
|
function tables_list() {
|
||||||
global $connection;
|
global $connection;
|
||||||
$collections = array();
|
$collections = array();
|
||||||
foreach ($connection->executeCommand($connection->_db_name, array('listCollections' => 1)) as $result) {
|
foreach ($connection->executeCommand(array('listCollections' => 1)) as $result) {
|
||||||
$collections[$result->name] = 'table';
|
$collections[$result->name] = 'table';
|
||||||
}
|
}
|
||||||
return $collections;
|
return $collections;
|
||||||
@@ -147,7 +151,7 @@ if (isset($_GET["mongo"])) {
|
|||||||
function indexes($table, $connection2 = null) {
|
function indexes($table, $connection2 = null) {
|
||||||
global $connection;
|
global $connection;
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach ($connection->executeCommand($connection->_db_name, array('listIndexes' => $table)) as $index) {
|
foreach ($connection->executeCommand(array('listIndexes' => $table)) as $index) {
|
||||||
$descs = array();
|
$descs = array();
|
||||||
$columns = array();
|
$columns = array();
|
||||||
foreach (get_object_vars($index->key) as $column => $type) {
|
foreach (get_object_vars($index->key) as $column => $type) {
|
||||||
@@ -196,7 +200,7 @@ if (isset($_GET["mongo"])) {
|
|||||||
function found_rows($table_status, $where) {
|
function found_rows($table_status, $where) {
|
||||||
global $connection;
|
global $connection;
|
||||||
$where = where_to_query($where);
|
$where = where_to_query($where);
|
||||||
$toArray = $connection->executeCommand($connection->_db_name, array('count' => $table_status['Name'], 'query' => $where))->toArray();
|
$toArray = $connection->executeCommand(array('count' => $table_status['Name'], 'query' => $where))->toArray();
|
||||||
return $toArray[0]->n;
|
return $toArray[0]->n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user