1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-08 07:36:44 +02:00

Use connection() instead of $connection

This commit is contained in:
Jakub Vrana
2025-03-29 21:16:28 +01:00
parent 168ea5ae6d
commit 712d96b22c
36 changed files with 130 additions and 196 deletions

View File

@@ -234,7 +234,6 @@ if (isset($_GET["clickhouse"])) {
}
function get_databases($flush) {
$connection = connection();
$result = get_rows('SHOW DATABASES');
$return = array();
@@ -276,9 +275,8 @@ if (isset($_GET["clickhouse"])) {
}
function table_status($name = "", $fast = false) {
$connection = connection();
$return = array();
$tables = get_rows("SELECT name, engine FROM system.tables WHERE database = " . q($connection->_db));
$tables = get_rows("SELECT name, engine FROM system.tables WHERE database = " . q(connection()->_db));
foreach ($tables as $table) {
$return[$table['name']] = array(
'Name' => $table['name'],
@@ -343,8 +341,7 @@ if (isset($_GET["clickhouse"])) {
}
function error() {
$connection = connection();
return h($connection->error);
return h(connection()->error);
}
function types(): array {

View File

@@ -130,9 +130,8 @@ if (isset($_GET["firebird"])) {
}
function tables_list() {
$connection = connection();
$query = 'SELECT RDB$RELATION_NAME FROM rdb$relations WHERE rdb$system_flag = 0';
$result = ibase_query($connection->_link, $query);
$result = ibase_query(connection()->_link, $query);
$return = array();
while ($row = ibase_fetch_assoc($result)) {
$return[$row['RDB$RELATION_NAME']] = 'table';
@@ -146,7 +145,6 @@ if (isset($_GET["firebird"])) {
}
function table_status($name = "", $fast = false) {
$connection = connection();
$return = array();
$data = ($name != "" ? array($name => 1) : tables_list());
foreach ($data as $index => $val) {
@@ -168,7 +166,6 @@ if (isset($_GET["firebird"])) {
}
function fields($table) {
$connection = connection();
$return = array();
$query = 'SELECT r.RDB$FIELD_NAME AS field_name,
r.RDB$DESCRIPTION AS field_description,
@@ -203,7 +200,7 @@ LEFT JOIN RDB$COLLATIONS coll ON f.RDB$COLLATION_ID = coll.RDB$COLLATION_ID
LEFT JOIN RDB$CHARACTER_SETS cset ON f.RDB$CHARACTER_SET_ID = cset.RDB$CHARACTER_SET_ID
WHERE r.RDB$RELATION_NAME = ' . q($table) . '
ORDER BY r.RDB$FIELD_POSITION';
$result = ibase_query($connection->_link, $query);
$result = ibase_query(connection()->_link, $query);
while ($row = ibase_fetch_assoc($result)) {
$return[trim($row['FIELD_NAME'])] = array(
"field" => trim($row["FIELD_NAME"]),
@@ -250,8 +247,7 @@ ORDER BY RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION';
}
function error() {
$connection = connection();
return h($connection->error);
return h(connection()->error);
}
function types(): array {

View File

@@ -440,25 +440,24 @@ if (isset($_GET["mongo"])) {
}
function alter_indexes($table, $alter) {
$connection = connection();
foreach ($alter as $val) {
list($type, $name, $set) = $val;
if ($set == "DROP") {
$return = $connection->_db->command(array("deleteIndexes" => $table, "index" => $name));
$return = connection()->_db->command(array("deleteIndexes" => $table, "index" => $name));
} else {
$columns = array();
foreach ($set as $column) {
$column = preg_replace('~ DESC$~', '', $column, 1, $count);
$columns[$column] = ($count ? -1 : 1);
}
$return = $connection->_db->selectCollection($table)->ensureIndex($columns, array(
$return = connection()->_db->selectCollection($table)->ensureIndex($columns, array(
"unique" => ($type == "UNIQUE"),
"name" => $name,
//! "sparse"
));
}
if ($return['errmsg']) {
$connection->error = $return['errmsg'];
connection()->error = $return['errmsg'];
return false;
}
}

View File

@@ -120,7 +120,6 @@ if (isset($_GET["simpledb"])) {
public $primary = "itemName()";
private function chunkRequest($ids, $action, $params, $expand = array()) {
$connection = connection();
foreach (array_chunk($ids, 25) as $chunk) {
$params2 = $params;
foreach ($chunk as $i => $id) {
@@ -133,7 +132,7 @@ if (isset($_GET["simpledb"])) {
return false;
}
}
$connection->affected_rows = count($ids);
connection()->affected_rows = count($ids);
return true;
}
@@ -150,10 +149,9 @@ if (isset($_GET["simpledb"])) {
}
function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, ?int $page = 0, bool $print = false) {
$connection = connection();
$connection->next = $_GET["next"];
connection()->next = $_GET["next"];
$return = parent::select($table, $select, $where, $group, $order, $limit, $page, $print);
$connection->next = 0;
connection()->next = 0;
return $return;
}
@@ -276,12 +274,11 @@ if (isset($_GET["simpledb"])) {
}
function tables_list() {
$connection = connection();
$return = array();
foreach (sdb_request_all('ListDomains', 'DomainName') as $table) {
$return[(string) $table] = 'table';
}
if ($connection->error && defined('Adminer\PAGE_HEADER')) {
if (connection()->error && defined('Adminer\PAGE_HEADER')) {
echo "<p class='error'>" . error() . "\n";
}
return $return;
@@ -315,8 +312,7 @@ if (isset($_GET["simpledb"])) {
}
function error() {
$connection = connection();
return h($connection->error);
return h(connection()->error);
}
function information_schema($db) {
@@ -382,7 +378,6 @@ if (isset($_GET["simpledb"])) {
}
function sdb_request($action, $params = array()) {
$connection = connection();
list($host, $params['AWSAccessKeyId'], $secret) = adminer()->credentials();
$params['Action'] = $action;
$params['Timestamp'] = gmdate('Y-m-d\TH:i:s+00:00');
@@ -404,7 +399,7 @@ if (isset($_GET["simpledb"])) {
'max_redirects' => 0,
))));
if (!$file) {
$connection->error = lang('Invalid credentials.');
connection()->error = lang('Invalid credentials.');
return false;
}
libxml_use_internal_errors(true);
@@ -412,15 +407,15 @@ if (isset($_GET["simpledb"])) {
$xml = simplexml_load_string($file);
if (!$xml) {
$error = libxml_get_last_error();
$connection->error = $error->message;
connection()->error = $error->message;
return false;
}
if ($xml->Errors) {
$error = $xml->Errors->Error;
$connection->error = "$error->Message ($error->Code)";
connection()->error = "$error->Message ($error->Code)";
return false;
}
$connection->error = '';
connection()->error = '';
$tag = $action . "Result";
return ($xml->$tag ?: true);
}