namespace Adminer;
-$drivers["mssql"] = "MS SQL";
+add_driver("mssql", "MS SQL");
if (isset($_GET["mssql"])) {
define('Adminer\DRIVER', "mssql");
<?php
namespace Adminer;
-$drivers = array("server" => "MySQL / MariaDB") + $drivers;
+SqlDriver::$drivers = array("server" => "MySQL / MariaDB") + SqlDriver::$drivers;
if (!defined('Adminer\DRIVER')) {
define('Adminer\DRIVER', "server"); // server - backwards compatibility
* @return string|Db string for error
*/
function connect(array $credentials) {
- global $drivers;
$connection = new Db;
$error = $connection->attach($credentials[0], $credentials[1], $credentials[2]);
if ($error) {
$connection->set_charset(charset($connection));
$connection->query("SET sql_quote_show_create = 1, autocommit = 1");
$connection->flavor = (preg_match('~MariaDB~', $connection->server_info) ? 'maria' : 'mysql');
- $drivers[DRIVER] = ($connection->flavor == 'maria' ? "MariaDB" : "MySQL");
+ add_driver(DRIVER, ($connection->flavor == 'maria' ? "MariaDB" : "MySQL"));
return $connection;
}
<?php
namespace Adminer;
-$drivers["oracle"] = "Oracle (beta)";
+add_driver("oracle", "Oracle (beta)");
if (isset($_GET["oracle"])) {
define('Adminer\DRIVER', "oracle");
<?php
namespace Adminer;
-$drivers["pgsql"] = "PostgreSQL";
+add_driver("pgsql", "PostgreSQL");
if (isset($_GET["pgsql"])) {
define('Adminer\DRIVER', "pgsql");
}
function connect($credentials) {
- global $drivers;
$connection = new Db;
$error = $connection->attach($credentials[0], $credentials[1], $credentials[2]);
if ($error) {
$connection->flavor = (preg_match('~CockroachDB~', $version) ? 'cockroach' : '');
$connection->server_info = preg_replace('~^\D*([\d.]+[-\w]*).*~', '\1', $version);
if ($connection->flavor == 'cockroach') { // we don't use "PostgreSQL / CockroachDB" by default because it's too long
- $drivers[DRIVER] = "CockroachDB";
+ add_driver(DRIVER, "CockroachDB");
}
return $connection;
}
<?php
namespace Adminer;
-$drivers["sqlite"] = "SQLite";
+add_driver("sqlite", "SQLite");
if (isset($_GET["sqlite"])) {
define('Adminer\DRIVER', "sqlite");
$is_sql = preg_match('~sql~', $_POST["format"]);
if ($is_sql) {
- echo "-- Adminer " . VERSION . " " . $drivers[DRIVER] . " " . str_replace("\n", " ", $connection->server_info) . " dump\n\n";
+ echo "-- Adminer " . VERSION . " " . get_driver(DRIVER) . " " . str_replace("\n", " ", $connection->server_info) . " dump\n\n";
if (JUSH == "sql") {
echo "SET NAMES utf8;
SET time_zone = '+00:00';
/** Print login form */
function loginForm(): void {
- global $drivers, $adminer;
+ global $adminer;
echo "<table class='layout'>\n";
// this is matched by compile.php
- echo $adminer->loginFormField('driver', '<tr><th>' . lang('System') . '<td>', html_select("auth[driver]", $drivers, DRIVER, "loginDriver(this);"));
+ echo $adminer->loginFormField('driver', '<tr><th>' . lang('System') . '<td>', html_select("auth[driver]", SqlDriver::$drivers, DRIVER, "loginDriver(this);"));
echo $adminer->loginFormField('server', '<tr><th>' . lang('Server') . '<td>', '<input name="auth[server]" value="' . h(SERVER) . '" title="hostname[:port]" placeholder="localhost" autocapitalize="off">');
// this is matched by compile.php
echo $adminer->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', '<input name="auth[username]" id="username" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">' . script("qs('#username').form['auth[driver]'].onchange();"));
* @param string $missing can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
*/
function navigation(string $missing): void {
- global $drivers, $connection, $adminer;
+ global $connection, $adminer;
echo "<h1>" . $adminer->name() . " <span class='version'>" . VERSION;
$new_version = $_COOKIE["adminer_version"];
echo " <a href='https://www.adminer.org/#download'" . target_blank() . " id='version'>" . (version_compare(VERSION, $new_version) < 0 ? h($new_version) : "") . "</a>";
$output = "";
foreach ((array) $_SESSION["pwds"] as $vendor => $servers) {
foreach ($servers as $server => $usernames) {
- $name = h(get_setting("vendor-$vendor-$server") ?: $drivers[$vendor]);
+ $name = h(get_setting("vendor-$vendor-$server") ?: get_driver($vendor));
foreach ($usernames as $username => $password) {
if ($password !== null) {
$dbs = $_SESSION["db"][$vendor][$server][$username];
if (is_object($connection)) {
$driver = new Driver($connection);
if ($connection->flavor) {
- save_settings(array("vendor-" . DRIVER . "-" . SERVER => $drivers[DRIVER]));
+ save_settings(array("vendor-" . DRIVER . "-" . SERVER => get_driver(DRIVER)));
}
}
}
exit;
}
-global $adminer, $connection, $driver, $drivers, $translations; // allows including Adminer inside a function
+global $adminer, $connection, $driver, $translations; // allows including Adminer inside a function
if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility
$_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"];
echo "<a href='" . h(ME) . "$key='>$val</a>\n";
}
}
- echo "<p>" . lang('%s version: %s through PHP extension %s', $drivers[DRIVER], "<b>" . h($connection->server_info) . "</b>", "<b>$connection->extension</b>") . "\n";
+ echo "<p>" . lang('%s version: %s through PHP extension %s', get_driver(DRIVER), "<b>" . h($connection->server_info) . "</b>", "<b>$connection->extension</b>") . "\n";
echo "<p>" . lang('Logged as: %s', "<b>" . h(logged_user()) . "</b>") . "\n";
if (isset($adminer->plugins) && is_array($adminer->plugins)) {
echo "<p>" . lang('Loaded plugins') . ":\n<ul>\n";
* @param string $title2 used after colon in title and heading, should be HTML escaped
*/
function page_header(string $title, string $error = "", $breadcrumb = array(), string $title2 = ""): void {
- global $adminer, $drivers;
+ global $adminer;
page_headers();
if (is_ajax() && $error) {
page_messages($error);
echo "<div id='content'>\n";
if ($breadcrumb !== null) {
$link = substr(preg_replace('~\b(username|db|ns)=[^&]*&~', '', ME), 0, -1);
- echo '<p id="breadcrumb"><a href="' . h($link ?: ".") . '">' . $drivers[DRIVER] . '</a> » ';
+ echo '<p id="breadcrumb"><a href="' . h($link ?: ".") . '">' . get_driver(DRIVER) . '</a> » ';
$link = substr(preg_replace('~\b(db|ns)=[^&]*&~', '', ME), 0, -1);
$server = $adminer->serverName(SERVER);
$server = ($server != "" ? $server : lang('Server'));
<?php
namespace Adminer;
-$drivers = array();
-
-/** Add a driver */
+/** Add or overwrite a driver */
function add_driver(string $id, string $name): void {
- global $drivers;
- $drivers[$id] = $name;
+ SqlDriver::$drivers[$id] = $name;
}
/** Get driver name */
function get_driver(string $id): string {
- global $drivers;
- return $drivers[$id];
+ return SqlDriver::$drivers[$id];
}
abstract class SqlDriver {
+ /** @var string[] */ static array $drivers = array();
/** @var list<string> */ static array $extensions = array(); // possible extensions
static string $jush; // JUSH identifier
/** Get authenticated URL */
function auth_url(string $vendor, ?string $server, string $username, string $db = null): string {
- global $drivers;
- $uri = remove_from_uri(implode("|", array_keys($drivers))
+ $uri = remove_from_uri(implode("|", array_keys(SqlDriver::$drivers))
. "|username|ext|"
. ($db !== null ? "db|" : "")
. ($vendor == 'mssql' || $vendor == 'pgsql' ? "" : "ns|") // we don't have access to support() here
$file = preg_replace("((\t*)" . preg_quote('if (support("' . $feature . '")') . ".*?\n\\1\\}( else)?)s", '', $file);
}
}
- if ($project != "editor" && count($drivers) == 1) {
- $file = str_replace('html_select("auth[driver]", $drivers, DRIVER, "loginDriver(this);")', 'input_hidden("auth[driver]", "' . ($vendor == "mysql" ? "server" : $vendor) . '") . "' . reset($drivers) . '"', $file, $count);
+ if ($project != "editor" && count(Adminer\SqlDriver::$drivers) == 1) {
+ $file = str_replace('html_select("auth[driver]", SqlDriver::$drivers, DRIVER, "loginDriver(this);")', 'input_hidden("auth[driver]", "' . ($vendor == "mysql" ? "server" : $vendor) . '") . "' . reset(Adminer\SqlDriver::$drivers) . '"', $file, $count);
if (!$count) {
echo "auth[driver] form field not found\n";
}
namespace Adminer;
include "../adminer/include/bootstrap.inc.php";
-$drivers[DRIVER] = lang('Login');
+add_driver(DRIVER, lang('Login'));
if (isset($_GET["select"]) && ($_POST["edit"] || $_POST["clone"]) && !$_POST["save"]) {
$_GET["edit"] = $_GET["select"];
- identifier: includeOnce.fileNotFound # ./adminer-plugins.php
- "~^Function (set_magic_quotes_runtime|mysql_)~" # PHP < 7 functions
- "~an unknown class OCI-?Lob~" # this looks like PHPStan bug
- - "~^Variable \\$(adminer|connection|driver|drivers|error|translations) might not be defined~" # declared in bootstrap.inc.php
+ - "~^Variable \\$(adminer|connection|driver|error|translations) might not be defined~" # declared in bootstrap.inc.php
- "~^Constant LANG not found~" # defined in lang.inc.php
- "~expects int, float given~" # this will work
- "~expects bool~" # truthy values