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

Call credentials() from connect()

This commit is contained in:
Jakub Vrana
2025-04-03 10:23:31 +02:00
parent 3693992650
commit 49eefa2585
3 changed files with 6 additions and 7 deletions

View File

@@ -41,7 +41,7 @@ if (!$error && $_POST) {
if (!$result) { if (!$result) {
echo "<p class='error'>" . error() . "\n"; echo "<p class='error'>" . error() . "\n";
} else { } else {
$connection2 = connect(adminer()->credentials()); $connection2 = connect();
if ($connection2) { if ($connection2) {
$connection2->select_db(DB); $connection2->select_db(DB);
} }

View File

@@ -24,10 +24,9 @@ function driver(): Driver {
return Driver::$instance; return Driver::$instance;
} }
/** Connect to the database /** Connect to the database */
* @param array{?string, string, string} $credentials [$server, $username, $password] function connect(): ?Db {
*/ $credentials = adminer()->credentials();
function connect(array $credentials): ?Db {
$return = Driver::connect($credentials[0], $credentials[1], $credentials[2]); $return = Driver::connect($credentials[0], $credentials[1], $credentials[2]);
return (is_object($return) ? $return : null); return (is_object($return) ? $return : null);
} }
@@ -831,7 +830,7 @@ function slow_query(string $query): array {
$slow_query = driver()->slowQuery($query, $timeout); $slow_query = driver()->slowQuery($query, $timeout);
$connection2 = null; $connection2 = null;
if (!$slow_query && support("kill")) { if (!$slow_query && support("kill")) {
$connection2 = connect(adminer()->credentials()); $connection2 = connect();
if ($connection2 && ($db == "" || $connection2->select_db($db))) { if ($connection2 && ($db == "" || $connection2->select_db($db))) {
$kill = get_val(connection_id(), 0, $connection2); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL $kill = get_val(connection_id(), 0, $connection2); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL
echo script("const timeout = setTimeout(() => { ajax('" . js_escape(ME) . "script=kill', function () {}, 'kill=$kill&token=" . get_token() . "'); }, 1000 * $timeout);"); echo script("const timeout = setTimeout(() => { ajax('" . js_escape(ME) . "script=kill', function () {}, 'kill=$kill&token=" . get_token() . "'); }, 1000 * $timeout);");

View File

@@ -55,7 +55,7 @@ if (!$error && $_POST) {
$delimiter = ";"; $delimiter = ";";
$offset = 0; $offset = 0;
$empty = true; $empty = true;
$connection2 = connect(adminer()->credentials()); // connection for exploring indexes and EXPLAIN (to not replace FOUND_ROWS()) //! PDO - silent error $connection2 = connect(); // connection for exploring indexes and EXPLAIN (to not replace FOUND_ROWS()) //! PDO - silent error
if ($connection2 && DB != "") { if ($connection2 && DB != "") {
$connection2->select_db(DB); $connection2->select_db(DB);
if ($_GET["ns"] != "") { if ($_GET["ns"] != "") {