Define SERVER always as string

This commit is contained in:
Jakub Vrana
2025-09-08 08:37:49 +02:00
parent 516530485d
commit 16f7080ff2
8 changed files with 22 additions and 22 deletions

View File

@@ -26,7 +26,7 @@ if (isset($_GET["mssql"])) {
$this->error = rtrim($this->error);
}
function attach(?string $server, string $username, string $password): string {
function attach(string $server, string $username, string $password): string {
$connection_info = array("UID" => $username, "PWD" => $password, "CharacterSet" => "UTF-8");
$ssl = adminer()->connectSsl();
if (isset($ssl["Encrypt"])) {
@@ -182,7 +182,7 @@ if (isset($_GET["mssql"])) {
class Db extends MssqlDb {
public $extension = "PDO_SQLSRV";
function attach(?string $server, string $username, string $password): string {
function attach(string $server, string $username, string $password): string {
list($host, $port) = host_port($server);
return $this->dsn("sqlsrv:Server=$host" . ($port ? ",$port" : ""), $username, $password);
}
@@ -192,7 +192,7 @@ if (isset($_GET["mssql"])) {
class Db extends MssqlDb {
public $extension = "PDO_DBLIB";
function attach(?string $server, string $username, string $password): string {
function attach(string $server, string $username, string $password): string {
list($host, $port) = host_port($server);
return $this->dsn("dblib:charset=utf8;host=$host" . ($port ? (is_numeric($port) ? ";port=" : ";unix_socket=") . $port : ""), $username, $password);
}
@@ -217,7 +217,7 @@ if (isset($_GET["mssql"])) {
public $generated = array("PERSISTED", "VIRTUAL");
public $onActions = "NO ACTION|CASCADE|SET NULL|SET DEFAULT";
static function connect(?string $server, string $username, string $password) {
static function connect(string $server, string $username, string $password) {
if ($server == "") {
$server = "localhost:1433";
}

View File

@@ -16,7 +16,7 @@ if (!defined('Adminer\DRIVER')) {
parent::init();
}
function attach(?string $server, string $username, string $password): string {
function attach(string $server, string $username, string $password): string {
mysqli_report(MYSQLI_REPORT_OFF); // stays between requests, not required since PHP 5.3.4
list($host, $port) = host_port($server);
$ssl = adminer()->connectSsl();
@@ -58,14 +58,14 @@ if (!defined('Adminer\DRIVER')) {
class Db extends SqlDb {
/** @var resource */ private $link;
function attach(?string $server, string $username, string $password): string {
function attach(string $server, string $username, string $password): string {
if (ini_bool("mysql.allow_local_infile")) {
return lang('Disable %s or enable %s or %s extensions.', "'mysql.allow_local_infile'", "MySQLi", "PDO_MySQL");
}
$this->link = @mysql_connect(
($server != "" ? $server : ini_get("mysql.default_host")),
("$server$username" != "" ? $username : ini_get("mysql.default_user")),
("$server$username$password" != "" ? $password : ini_get("mysql.default_password")),
($server . $username != "" ? $username : ini_get("mysql.default_user")),
($server . $username . $password != "" ? $password : ini_get("mysql.default_password")),
true,
131072 // CLIENT_MULTI_RESULTS for CALL
);
@@ -158,7 +158,7 @@ if (!defined('Adminer\DRIVER')) {
class Db extends PdoDb {
public $extension = "PDO_MySQL";
function attach(?string $server, string $username, string $password): string {
function attach(string $server, string $username, string $password): string {
$options = array(\PDO::MYSQL_ATTR_LOCAL_INFILE => false);
$ssl = adminer()->connectSsl();
if ($ssl) {
@@ -212,7 +212,7 @@ if (!defined('Adminer\DRIVER')) {
public $functions = array("char_length", "date", "from_unixtime", "lower", "round", "floor", "ceil", "sec_to_time", "time_to_sec", "upper");
public $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
static function connect(?string $server, string $username, string $password) {
static function connect(string $server, string $username, string $password) {
$connection = parent::connect($server, $username, $password);
if (is_string($connection)) {
if (function_exists('iconv') && !is_utf8($connection) && strlen($s = iconv("windows-1250", "utf-8", $connection)) > strlen($connection)) { // windows-1250 - most common Windows encoding

View File

@@ -20,7 +20,7 @@ if (isset($_GET["oracle"])) {
$this->error = $error;
}
function attach(?string $server, string $username, string $password): string {
function attach(string $server, string $username, string $password): string {
$this->link = @oci_new_connect($username, $password, $server, "AL32UTF8");
if ($this->link) {
$this->server_info = oci_server_version($this->link);
@@ -110,7 +110,7 @@ if (isset($_GET["oracle"])) {
public $extension = "PDO_OCI";
public $_current_db;
function attach(?string $server, string $username, string $password): string {
function attach(string $server, string $username, string $password): string {
return $this->dsn("oci:dbname=//$server;charset=AL32UTF8", $username, $password);
}

View File

@@ -20,7 +20,7 @@ if (isset($_GET["pgsql"])) {
$this->error = $error;
}
function attach(?string $server, string $username, string $password): string {
function attach(string $server, string $username, string $password): string {
$db = adminer()->database();
set_error_handler(array($this, '_error'));
list($host, $port) = host_port(addcslashes($server, "'\\"));
@@ -144,7 +144,7 @@ if (isset($_GET["pgsql"])) {
public $extension = "PDO_PgSQL";
public $timeout = 0;
function attach(?string $server, string $username, string $password): string {
function attach(string $server, string $username, string $password): string {
$db = adminer()->database();
list($host, $port) = host_port(addcslashes($server, "'\\"));
//! client_encoding is supported since 9.1, but we can't yet use min_version here
@@ -212,7 +212,7 @@ if (isset($_GET["pgsql"])) {
public string $nsOid = "(SELECT oid FROM pg_namespace WHERE nspname = current_schema())";
static function connect(?string $server, string $username, string $password) {
static function connect(string $server, string $username, string $password) {
$connection = parent::connect($server, $username, $password);
if (is_string($connection)) {
return $connection;

View File

@@ -11,7 +11,7 @@ if (isset($_GET["sqlite"])) {
public $extension = "SQLite3";
private $link;
function attach(?string $filename, string $username, string $password): string {
function attach(string $filename, string $username, string $password): string {
$this->link = new \SQLite3($filename);
$version = $this->link->version();
$this->server_info = $version["versionString"];
@@ -75,7 +75,7 @@ if (isset($_GET["sqlite"])) {
abstract class SqliteDb extends PdoDb {
public $extension = "PDO_SQLite";
function attach(?string $filename, string $username, string $password): string {
function attach(string $filename, string $username, string $password): string {
$this->dsn(DRIVER . ":$filename", "", "");
$this->query("PRAGMA foreign_keys = 1");
$this->query("PRAGMA busy_timeout = 500");
@@ -87,7 +87,7 @@ if (isset($_GET["sqlite"])) {
if (class_exists('Adminer\SqliteDb')) {
class Db extends SqliteDb {
function attach(?string $filename, string $username, string $password): string {
function attach(string $filename, string $username, string $password): string {
parent::attach($filename, $username, $password);
$this->query("PRAGMA foreign_keys = 1");
$this->query("PRAGMA busy_timeout = 500");
@@ -122,7 +122,7 @@ if (isset($_GET["sqlite"])) {
public $functions = array("hex", "length", "lower", "round", "unixepoch", "upper");
public $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
static function connect(?string $server, string $username, string $password) {
static function connect(string $server, string $username, string $password) {
if ($password != "") {
return lang('Database does not support password.');
}

View File

@@ -91,7 +91,7 @@ Adminer::$instance =
include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
define('Adminer\JUSH', Driver::$jush);
define('Adminer\SERVER', $_GET[DRIVER]); // read from pgsql=localhost, '' means default server, null means no server
define('Adminer\SERVER', "" . $_GET[DRIVER]); // read from pgsql=localhost, '' means default server
define('Adminer\DB', "$_GET[db]"); // for the sake of speed and size
define(
'Adminer\ME',

View File

@@ -18,7 +18,7 @@ abstract class SqlDb {
/** Connect to server
* @return string error message
*/
abstract function attach(?string $server, string $username, string $password): string;
abstract function attach(string $server, string $username, string $password): string;
/** Quote string to use in SQL
* @return string escaped string enclosed in '

View File

@@ -34,7 +34,7 @@ abstract class SqlDriver {
/** Connect to the database
* @return Db|string string for error
*/
static function connect(?string $server, string $username, string $password) {
static function connect(string $server, string $username, string $password) {
$connection = new Db;
return ($connection->attach($server, $username, $password) ?: $connection);
}