MongoDB: Consolidate code
This commit is contained in:
parent
70afe70b72
commit
5f4d407f2e
|
@ -9,24 +9,8 @@ if (isset($_GET["mongo"])) {
|
||||||
class Min_DB {
|
class Min_DB {
|
||||||
var $extension = "Mongo", $server_info = MongoClient::VERSION, $error, $last_id, $_link, $_db;
|
var $extension = "Mongo", $server_info = MongoClient::VERSION, $error, $last_id, $_link, $_db;
|
||||||
|
|
||||||
function connect($server, $username, $password) {
|
function connect($uri, $options) {
|
||||||
global $adminer;
|
$this->_link = @new MongoClient($uri, $options);
|
||||||
$db = $adminer->database();
|
|
||||||
$options = array();
|
|
||||||
if ($username != "") {
|
|
||||||
$options["username"] = $username;
|
|
||||||
$options["password"] = $password;
|
|
||||||
}
|
|
||||||
if ($db != "") {
|
|
||||||
$options["db"] = $db;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$this->_link = @new MongoClient("mongodb://$server", $options);
|
|
||||||
return true;
|
|
||||||
} catch (Exception $ex) {
|
|
||||||
$this->error = $ex->getMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function query($query) {
|
function query($query) {
|
||||||
|
@ -171,10 +155,6 @@ if (isset($_GET["mongo"])) {
|
||||||
return array_fill_keys($connection->_db->getCollectionNames(true), 'table');
|
return array_fill_keys($connection->_db->getCollectionNames(true), 'table');
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_database($db, $collation) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function drop_databases($databases) {
|
function drop_databases($databases) {
|
||||||
global $connection;
|
global $connection;
|
||||||
foreach ($databases as $db) {
|
foreach ($databases as $db) {
|
||||||
|
@ -223,25 +203,9 @@ if (isset($_GET["mongo"])) {
|
||||||
var $_link;
|
var $_link;
|
||||||
var $_db, $_db_name;
|
var $_db, $_db_name;
|
||||||
|
|
||||||
function connect($server, $username, $password) {
|
function connect($uri, $options) {
|
||||||
global $adminer;
|
|
||||||
$db = $adminer->database();
|
|
||||||
$options = array();
|
|
||||||
if ($username != "") {
|
|
||||||
$options["username"] = $username;
|
|
||||||
$options["password"] = $password;
|
|
||||||
}
|
|
||||||
if ($db != "") {
|
|
||||||
$options["db"] = $db;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$class = 'MongoDB\Driver\Manager';
|
$class = 'MongoDB\Driver\Manager';
|
||||||
$this->_link = new $class("mongodb://$server", $options);
|
$this->_link = new $class($uri, $options);
|
||||||
return true;
|
|
||||||
} catch (Exception $ex) {
|
|
||||||
$this->error = $ex->getMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function query($query) {
|
function query($query) {
|
||||||
|
@ -249,13 +213,8 @@ if (isset($_GET["mongo"])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function select_db($database) {
|
function select_db($database) {
|
||||||
try {
|
|
||||||
$this->_db_name = $database;
|
$this->_db_name = $database;
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception $ex) {
|
|
||||||
$this->error = $ex->getMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function quote($string) {
|
function quote($string) {
|
||||||
|
@ -440,10 +399,6 @@ if (isset($_GET["mongo"])) {
|
||||||
return $collections;
|
return $collections;
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_database($db, $collation) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function drop_databases($databases) {
|
function drop_databases($databases) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -626,6 +581,10 @@ if (isset($_GET["mongo"])) {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function create_database($db, $collation) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function last_id() {
|
function last_id() {
|
||||||
global $connection;
|
global $connection;
|
||||||
return $connection->last_id;
|
return $connection->last_id;
|
||||||
|
@ -649,12 +608,24 @@ if (isset($_GET["mongo"])) {
|
||||||
function connect() {
|
function connect() {
|
||||||
global $adminer;
|
global $adminer;
|
||||||
$connection = new Min_DB;
|
$connection = new Min_DB;
|
||||||
$credentials = $adminer->credentials();
|
list($server, $username, $password) = $adminer->credentials();
|
||||||
if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
|
$options = array();
|
||||||
return $connection;
|
if ($username != "") {
|
||||||
|
$options["username"] = $username;
|
||||||
|
$options["password"] = $password;
|
||||||
}
|
}
|
||||||
|
$db = $adminer->database();
|
||||||
|
if ($db != "") {
|
||||||
|
$options["db"] = $db;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$connection->connect("mongodb://$server", $options);
|
||||||
|
return $connection;
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
$connection->error = $ex->getMessage();
|
||||||
return $connection->error;
|
return $connection->error;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function alter_indexes($table, $alter) {
|
function alter_indexes($table, $alter) {
|
||||||
global $connection;
|
global $connection;
|
||||||
|
|
Loading…
Reference in a new issue