]> git.joonet.de Git - adminer.git/commitdiff
Use common parent for Db
authorJakub Vrana <jakub@vrana.cz>
Thu, 27 Mar 2025 14:28:14 +0000 (15:28 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 27 Mar 2025 17:39:47 +0000 (18:39 +0100)
18 files changed:
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/bootstrap.inc.php
adminer/include/db.inc.php [new file with mode: 0644]
adminer/include/driver.inc.php
adminer/include/lang.inc.php
adminer/include/pdo.inc.php
compile.php
phpstan.neon
plugins/drivers/clickhouse.php
plugins/drivers/elastic.php
plugins/drivers/firebird.php
plugins/drivers/imap.php
plugins/drivers/mongo.php
plugins/drivers/simpledb.php

index 061547aa30ff5837f15f630f50a458f951759037..87905cc0ff9297f9f741d2bf4b327097d54b04fd 100644 (file)
@@ -12,8 +12,8 @@ $drivers["mssql"] = "MS SQL";
 if (isset($_GET["mssql"])) {
        define('Adminer\DRIVER', "mssql");
        if (extension_loaded("sqlsrv") && $_GET["ext"] != "pdo") {
-               class Db {
-                       public $extension = "sqlsrv", $flavor = '', $server_info, $affected_rows, $errno, $error;
+               class Db extends SqlDb {
+                       public $extension = "sqlsrv";
                        private $link, $result;
 
                        private function get_error() {
@@ -95,15 +95,6 @@ if (isset($_GET["mssql"])) {
                        function next_result() {
                                return $this->result ? sqlsrv_next_result($this->result) : null;
                        }
-
-                       function result($query, $field = 0) {
-                               $result = $this->query($query);
-                               if (!is_object($result)) {
-                                       return false;
-                               }
-                               $row = $result->fetch_row();
-                               return $row[$field];
-                       }
                }
 
                class Result {
@@ -168,7 +159,7 @@ if (isset($_GET["mssql"])) {
                }
 
        } else {
-               class MssqlDb extends PdoDb {
+               abstract class MssqlDb extends PdoDb {
                        function select_db($database) {
                                // database selection is separated from the connection so dbname in DSN can't be used
                                return $this->query(use_sql($database));
index d8e558072ce818d0a573b81bd5e842ed4d16290e..26bd220e0e191adc6a79425772d9dfe3fbeb83ef 100644 (file)
@@ -47,7 +47,7 @@ if (!defined('Adminer\DRIVER')) {
 
                        function result($query, $field = 0) {
                                $result = $this->query($query);
-                               if (!$result) {
+                               if (!is_object($result)) {
                                        return false;
                                }
                                $row = $result->fetch_array();
@@ -60,24 +60,9 @@ if (!defined('Adminer\DRIVER')) {
                }
 
        } elseif (extension_loaded("mysql") && !((ini_bool("sql.safe_mode") || ini_bool("mysql.allow_local_infile")) && extension_loaded("pdo_mysql"))) {
-               class Db {
-                       /** @var string */ public $extension = "MySQL"; // extension name
-                       /** @var string */ public $flavor = ''; // different vendor with the same API; e.g. MariaDB; usually stays empty
-                       /** @var string */ public $server_info; // server version
-                       /** @var int */ public $affected_rows; // number of affected rows
-                       /** @var string */ public $info; // see https://php.net/mysql_info
-                       /** @var int */ public $errno; // last error code
-                       /** @var string */ public $error; // last error message
-
-                       /** @var \mysqli */ private $link;
-                       /** @var Result */ private $result;
-
-                       /** Connect to server
-                       * @param string
-                       * @param string
-                       * @param string
-                       * @return bool
-                       */
+               class Db extends SqlDb {
+                       /** @var resource */ private $link;
+
                        function connect($server, $username, $password) {
                                if (ini_bool("mysql.allow_local_infile")) {
                                        $this->error = lang('Disable %s or enable %s or %s extensions.', "'mysql.allow_local_infile'", "MySQLi", "PDO_MySQL");
@@ -113,27 +98,14 @@ if (!defined('Adminer\DRIVER')) {
                                return $this->query("SET NAMES $charset");
                        }
 
-                       /** Quote string to use in SQL
-                       * @param string
-                       * @return string escaped string enclosed in '
-                       */
                        function quote($string) {
                                return "'" . mysql_real_escape_string($string, $this->link) . "'";
                        }
 
-                       /** Select database
-                       * @param string
-                       * @return bool
-                       */
                        function select_db($database) {
                                return mysql_select_db($database, $this->link);
                        }
 
-                       /** Send query
-                       * @param string
-                       * @param bool
-                       * @return Result|bool
-                       */
                        function query($query, $unbuffered = false) {
                                $result = @($unbuffered ? mysql_unbuffered_query($query, $this->link) : mysql_query($query, $this->link)); // @ - mute mysql.trace_mode
                                $this->error = "";
@@ -149,39 +121,6 @@ if (!defined('Adminer\DRIVER')) {
                                }
                                return new Result($result);
                        }
-
-                       /** Send query with more resultsets
-                       * @param string
-                       * @return Result|bool
-                       */
-                       function multi_query($query) {
-                               return $this->result = $this->query($query);
-                       }
-
-                       /** Get current resultset
-                       * @return Result
-                       */
-                       function store_result() {
-                               return $this->result;
-                       }
-
-                       /** Fetch next resultset
-                       * @return bool
-                       */
-                       function next_result() {
-                               // MySQL extension doesn't support multiple results
-                               return false;
-                       }
-
-                       /** Get single field from result
-                       * @param string
-                       * @param int
-                       * @return string
-                       */
-                       function result($query, $field = 0) {
-                               $result = $this->query($query);
-                               return ($result ? $result->fetch_column($field) : false);
-                       }
                }
 
                class Result {
@@ -198,27 +137,19 @@ if (!defined('Adminer\DRIVER')) {
                        }
 
                        /** Fetch next row as associative array
-                       * @return string[]
+                       * @return array<?string>
                        */
                        function fetch_assoc() {
                                return mysql_fetch_assoc($this->result);
                        }
 
                        /** Fetch next row as numbered array
-                       * @return list<string>
+                       * @return list<?string>
                        */
                        function fetch_row() {
                                return mysql_fetch_row($this->result);
                        }
 
-                       /** Fetch a single column
-                       * @param int
-                       * @return string or false if there are no rows
-                       */
-                       function fetch_column($field) {
-                               return ($this->num_rows ? mysql_result($this->result, 0, $field) : false);
-                       }
-
                        /** Fetch next field
                        * @return object properties: name, type (0 number, 15 varchar, 254 char), charsetnr (63 binary); optionally: table, orgtable, orgname
                        */
@@ -268,7 +199,7 @@ if (!defined('Adminer\DRIVER')) {
                        }
 
                        function set_charset($charset) {
-                               $this->query("SET NAMES $charset"); // charset in DSN is ignored before PHP 5.3.6
+                               return $this->query("SET NAMES $charset"); // charset in DSN is ignored before PHP 5.3.6
                        }
 
                        function select_db($database) {
@@ -1179,7 +1110,7 @@ if (!defined('Adminer\DRIVER')) {
        }
 
        /** Check whether a feature is supported
-       * @param string "check|comment|copy|database|descidx|drop_col|dump|event|indexes|kill|materializedview|partitioning|privileges|procedure|processlist|routine|scheme|sequence|status|table|trigger|type|variables|view|view_trigger"
+       * @param literal-string "check|comment|copy|database|descidx|drop_col|dump|event|indexes|kill|materializedview|partitioning|privileges|procedure|processlist|routine|scheme|sequence|status|table|trigger|type|variables|view|view_trigger"
        * @return bool
        */
        function support($feature) {
index b7eff9537328620d701d99b30c948eb927dcc88a..af28f1b7921677a675b7839803deef0b0c33681a 100644 (file)
@@ -6,10 +6,10 @@ $drivers["oracle"] = "Oracle (beta)";
 if (isset($_GET["oracle"])) {
        define('Adminer\DRIVER', "oracle");
        if (extension_loaded("oci8") && $_GET["ext"] != "pdo") {
-               class Db {
-                       public $extension = "oci8", $flavor = '', $server_info, $affected_rows, $errno, $error;
+               class Db extends SqlDb {
+                       public $extension = "oci8";
                        public $_current_db;
-                       private $link, $result;
+                       private $link;
 
                        function _error($errno, $error) {
                                if (ini_bool("html_errors")) {
@@ -60,23 +60,6 @@ if (isset($_GET["oracle"])) {
                                }
                                return $return;
                        }
-
-                       function multi_query($query) {
-                               return $this->result = $this->query($query);
-                       }
-
-                       function store_result() {
-                               return $this->result;
-                       }
-
-                       function next_result() {
-                               return false;
-                       }
-
-                       function result($query, $field = 0) {
-                               $result = $this->query($query);
-                               return (is_object($result) ? $result->fetch_column($field) : false);
-                       }
                }
 
                class Result {
@@ -104,10 +87,6 @@ if (isset($_GET["oracle"])) {
                                return $this->convert(oci_fetch_row($this->result));
                        }
 
-                       function fetch_column($field) {
-                               return (oci_fetch($this->result) ? oci_result($this->result, $field + 1) : false);
-                       }
-
                        function fetch_field() {
                                $column = $this->offset++;
                                $return = new \stdClass;
index 490ffdfe67080b37dcc39a67f134cb12dd07a7e0..253d60ca237ea194f5b3ce6a35e4851fc9f8439f 100644 (file)
@@ -6,9 +6,9 @@ $drivers["pgsql"] = "PostgreSQL";
 if (isset($_GET["pgsql"])) {
        define('Adminer\DRIVER', "pgsql");
        if (extension_loaded("pgsql") && $_GET["ext"] != "pdo") {
-               class Db {
-                       public $extension = "PgSQL", $flavor = '', $server_info, $affected_rows, $error, $timeout;
-                       private $link, $result, $string, $database = true;
+               class Db extends SqlDb {
+                       public $extension = "PgSQL", $timeout;
+                       private $link, $string, $database = true;
 
                        function _error($errno, $error) {
                                if (ini_bool("html_errors")) {
@@ -86,24 +86,6 @@ if (isset($_GET["pgsql"])) {
                                return $return;
                        }
 
-                       function multi_query($query) {
-                               return $this->result = $this->query($query);
-                       }
-
-                       function store_result() {
-                               return $this->result;
-                       }
-
-                       function next_result() {
-                               // PgSQL extension doesn't support multiple results
-                               return false;
-                       }
-
-                       function result($query, $field = 0) {
-                               $result = $this->query($query);
-                               return ($result ? $result->fetch_column($field) : false);
-                       }
-
                        function warnings() {
                                return h(pg_last_notice($this->link)); // second parameter is available since PHP 7.1.0
                        }
@@ -126,10 +108,6 @@ if (isset($_GET["pgsql"])) {
                                return pg_fetch_row($this->result);
                        }
 
-                       function fetch_column($field) {
-                               return ($this->num_rows ? pg_fetch_result($this->result, 0, $field) : false);
-                       }
-
                        function fetch_field() {
                                $column = $this->offset++;
                                $return = new \stdClass;
@@ -176,7 +154,9 @@ if (isset($_GET["pgsql"])) {
                                return $return;
                        }
 
-                       // warnings() not implemented in PDO_PgSQL as of PHP 7.2.1
+                       function warnings() {
+                               // not implemented in PDO_PgSQL as of PHP 7.2.1
+                       }
 
                        function close() {
                        }
index bdd6cf585eb1dbd5d7348667cc1e4bd2cdb52e9a..c0f52c8f9b333db9c5c9e30c7973fdce9f093669 100644 (file)
@@ -7,17 +7,18 @@ if (isset($_GET["sqlite"])) {
        define('Adminer\DRIVER', "sqlite");
        if (class_exists("SQLite3") && $_GET["ext"] != "pdo") {
 
-               class SqliteDb {
-                       public $extension = "SQLite3", $flavor = '', $server_info, $affected_rows, $errno, $error;
-                       private $link, $result;
+               abstract class SqliteDb extends SqlDb {
+                       public $extension = "SQLite3";
+                       private $link;
 
-                       function __construct($filename) {
+                       function connect($filename, $username = '', $password = '') {
                                $this->link = new \SQLite3($filename);
                                $version = $this->link->version();
                                $this->server_info = $version["versionString"];
+                               return true;
                        }
 
-                       function query($query) {
+                       function query($query, $unbuffered = false) {
                                $result = @$this->link->query($query);
                                $this->error = "";
                                if (!$result) {
@@ -37,28 +38,6 @@ if (isset($_GET["sqlite"])) {
                                        : "x'" . first(unpack('H*', $string)) . "'"
                                );
                        }
-
-
-                       function multi_query($query) {
-                               return $this->result = $this->query($query);
-                       }
-
-                       function store_result() {
-                               return $this->result;
-                       }
-
-                       function next_result() {
-                               return false;
-                       }
-
-                       function result($query, $field = 0) {
-                               $result = $this->query($query);
-                               if (!is_object($result)) {
-                                       return false;
-                               }
-                               $row = $result->fetch_row();
-                               return $row ? $row[$field] : false;
-                       }
                }
 
                class Result {
@@ -93,15 +72,14 @@ if (isset($_GET["sqlite"])) {
                }
 
        } elseif (extension_loaded("pdo_sqlite")) {
-               class SqliteDb extends PdoDb {
+               abstract class SqliteDb extends PdoDb {
                        public $extension = "PDO_SQLite";
 
-                       function __construct($filename) {
+                       function connect($filename, $username = '', $password = '') {
                                $this->dsn(DRIVER . ":$filename", "", "");
-                       }
-
-                       function select_db($db) {
-                               return false;
+                               $this->query("PRAGMA foreign_keys = 1");
+                               $this->query("PRAGMA busy_timeout = 500");
+                               return true;
                        }
                }
 
@@ -109,17 +87,16 @@ if (isset($_GET["sqlite"])) {
 
        if (class_exists('Adminer\SqliteDb')) {
                class Db extends SqliteDb {
-                       function __construct() {
-                               parent::__construct(":memory:");
+                       function connect($filename, $username = '', $password = '') {
+                               parent::connect($filename);
                                $this->query("PRAGMA foreign_keys = 1");
+                               $this->query("PRAGMA busy_timeout = 500");
+                               return true;
                        }
 
                        function select_db($filename) {
-                               if (is_readable($filename) && $this->query("ATTACH " . $this->quote(preg_match("~(^[/\\\\]|:)~", $filename) ? $filename : dirname($_SERVER["SCRIPT_FILENAME"]) . "/$filename") . " AS a")) { // is_readable - SQLite 3
-                                       parent::__construct($filename);
-                                       $this->query("PRAGMA foreign_keys = 1");
-                                       $this->query("PRAGMA busy_timeout = 500");
-                                       return true;
+                               if (is_readable($filename) && $this->query("ATTACH " . $this->quote(preg_match("~(^[/\\\\]|:)~", $filename) ? $filename : dirname($_SERVER["SCRIPT_FILENAME"]) . "/$filename") . " AS a")) {
+                                       return self::connect($filename);
                                }
                                return false;
                        }
@@ -197,7 +174,9 @@ if (isset($_GET["sqlite"])) {
                if ($password != "") {
                        return lang('Database does not support password.');
                }
-               return new Db;
+               $connection = new Db;
+               $connection->connect(":memory:", "", "");
+               return $connection;
        }
 
        function get_databases($flush) {
@@ -392,7 +371,8 @@ if (isset($_GET["sqlite"])) {
                        return false;
                }
                try {
-                       $link = new SqliteDb($db);
+                       $link = new Db();
+                       $link->connect($db);
                } catch (\Exception $ex) {
                        $connection->error = $ex->getMessage();
                        return false;
@@ -476,7 +456,7 @@ if (isset($_GET["sqlite"])) {
        * @param string new name
        * @param list<list<string>> [process_field()], empty to preserve
        * @param string[] [$original => idf_escape($new_column)], empty to preserve
-       * @param string [format_foreign_key()], empty to preserve
+       * @param string[] [format_foreign_key()], empty to preserve
        * @param int set auto_increment to this value, 0 to preserve
        * @param list<array{string, string, list<string>|'DROP'}> [[$type, $name, $columns]], empty to preserve
        * @param string CHECK constraint to drop
index 6198404a501680f6c439060463aa8adaf6c16822..848d487cb678e619b879d6f8d1db374426ddb1da 100644 (file)
@@ -70,6 +70,7 @@ if (function_exists("get_magic_quotes_runtime") && get_magic_quotes_runtime()) {
 
 include "../adminer/include/lang.inc.php";
 include "../adminer/lang/$LANG.inc.php";
+include "../adminer/include/db.inc.php";
 include "../adminer/include/pdo.inc.php";
 include "../adminer/include/driver.inc.php";
 include "../adminer/drivers/sqlite.inc.php";
diff --git a/adminer/include/db.inc.php b/adminer/include/db.inc.php
new file mode 100644 (file)
index 0000000..e71e776
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+namespace Adminer;
+
+// this could be interface when "Db extends \mysqli" can have compatible type declarations (PHP 7)
+// interfaces can include properties only since PHP 8.4
+abstract class SqlDb {
+       /** @var string */ public $extension; // extension name
+       /** @var string */ public $flavor; // different vendor with the same API, e.g. MariaDB; usually stays empty
+       /** @var string */ public $server_info; // server version
+       /** @var int */ public $affected_rows; // number of affected rows
+       /** @var string */ public $info; // see https://php.net/mysql_info
+       /** @var int */ public $errno; // last error code
+       /** @var string */ public $error; // last error message
+       /** @var Result|bool */ protected $multi; // used for multiquery
+
+       /** Connect to server
+       * @param string
+       * @param string
+       * @param string
+       * @return bool
+       */
+       abstract function connect($server, $username, $password);
+
+       /** Quote string to use in SQL
+       * @param string
+       * @return string escaped string enclosed in '
+       */
+       abstract function quote($string);
+
+       /** Select database
+       * @param string
+       * @return bool
+       */
+       abstract function select_db($database);
+
+       /** Send query
+       * @param string
+       * @param bool
+       * @return Result|bool
+       */
+       abstract function query($query, $unbuffered = false);
+
+       /** Send query with more resultsets
+       * @param string
+       * @return Result|bool
+       */
+       function multi_query($query) {
+               return $this->multi = $this->query($query);
+       }
+
+       /** Get current resultset
+       * @return Result|bool
+       */
+       function store_result() {
+               return $this->multi;
+       }
+
+       /** Fetch next resultset
+       * @return bool
+       */
+       function next_result() {
+               return false;
+       }
+
+       /** Get single field from result
+       * @param string
+       * @param int
+       * @return string|bool
+       */
+       function result($query, $field = 0) {
+               $result = $this->query($query);
+               if (!is_object($result)) {
+                       return false;
+               }
+               $row = $result->fetch_row();
+               return ($row ? $row[$field] : false);
+       }
+}
index dfc33352abcc00ef28ca18e7642f3061dba4da33..30638271d4fbbb6e6b520b583e361278a6307f55 100644 (file)
@@ -79,7 +79,7 @@ abstract class SqlDriver {
        * @param list<string> result of $adminer->selectSearchProcess()
        * @param list<string> result of $adminer->selectColumnsProcess()[1]
        * @param list<string> result of $adminer->selectOrderProcess()
-       * @param int result of $adminer->selectLimitProcess()
+       * @param int|numeric-string result of $adminer->selectLimitProcess()
        * @param int index of page starting at zero
        * @param bool whether to print the query
        * @return Result|false
index da2436e0c4b8b585271b8ebc6b93fcb7b0a296e4..c9354da3c07a8ebc26cb9685ca8722b692899227 100644 (file)
@@ -64,8 +64,8 @@ function get_lang() {
 * @param float|string
 * @return string
 */
-// this is matched by compile.php
 function lang($idf, $number = null) {
+       // this is matched by compile.php
        global $LANG, $translations;
        $translation = ($translations[$idf] ?: $idf);
        if (is_array($translation)) {
index a03f7c1a7171418277ee7bddc5c4ff813b8838b5..2c71ca95691347f998d10607c7e67df7f073e315 100644 (file)
@@ -3,14 +3,19 @@ namespace Adminer;
 
 // PDO can be used in several database drivers
 if (extension_loaded('pdo')) {
-       abstract class PdoDb {
-               public $flavor = '', $server_info, $affected_rows, $errno, $error;
-               protected $pdo;
-               private $result;
+       abstract class PdoDb extends SqlDb {
+               /** @var \PDO */ protected $pdo;
 
+               /** Connect to server using DSN
+               * @param string
+               * @param string
+               * @param string
+               * @param mixed[]
+               * @return void
+               */
                function dsn($dsn, $username, $password, $options = array()) {
                        $options[\PDO::ATTR_ERRMODE] = \PDO::ERRMODE_SILENT;
-                       $options[\PDO::ATTR_STATEMENT_CLASS] = array('Adminer\PdoDbStatement');
+                       $options[\PDO::ATTR_STATEMENT_CLASS] = array('Adminer\PdoResult');
                        try {
                                $this->pdo = new \PDO($dsn, $username, $password, $options);
                        } catch (\Exception $ex) {
@@ -19,13 +24,12 @@ if (extension_loaded('pdo')) {
                        $this->server_info = @$this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION);
                }
 
-               abstract function select_db($database);
-
                function quote($string) {
                        return $this->pdo->quote($string);
                }
 
                function query($query, $unbuffered = false) {
+                       /** @var Result|bool */
                        $result = $this->pdo->query($query);
                        $this->error = "";
                        if (!$result) {
@@ -39,13 +43,9 @@ if (extension_loaded('pdo')) {
                        return $result;
                }
 
-               function multi_query($query) {
-                       return $this->result = $this->query($query);
-               }
-
                function store_result($result = null) {
                        if (!$result) {
-                               $result = $this->result;
+                               $result = $this->multi;
                                if (!$result) {
                                        return false;
                                }
@@ -59,24 +59,15 @@ if (extension_loaded('pdo')) {
                }
 
                function next_result() {
-                       if (!$this->result) {
-                               return false;
-                       }
-                       $this->result->_offset = 0;
-                       return @$this->result->nextRowset(); // @ - PDO_PgSQL doesn't support it
-               }
-
-               function result($query, $field = 0) {
-                       $result = $this->query($query);
-                       if (!$result) {
+                       if (!is_object($this->multi)) {
                                return false;
                        }
-                       $row = $result->fetch();
-                       return $row ? $row[$field] : false;
+                       $this->multi->_offset = 0;
+                       return @$this->multi->nextRowset(); // @ - PDO_PgSQL doesn't support it
                }
        }
 
-       class PdoDbStatement extends \PDOStatement {
+       class PdoResult extends \PDOStatement {
                public $_offset = 0, $num_rows;
 
                function fetch_assoc() {
@@ -87,10 +78,6 @@ if (extension_loaded('pdo')) {
                        return $this->fetch(\PDO::FETCH_NUM);
                }
 
-               function fetch_column($field) {
-                       return $this->fetchColumn($field);
-               }
-
                function fetch_field() {
                        $row = (object) $this->getColumnMeta($this->_offset++);
                        $type = $row->pdo_type;
index 64cd48fabd45fc1bfa903d10fa0d4c5ce480c40a..224ab08c3b96221eaf6981801eb5ca686cb3f749 100755 (executable)
@@ -281,6 +281,7 @@ if ($_SERVER["argv"][1]) {
        exit(1);
 }
 
+include __DIR__ . "/adminer/include/db.inc.php";
 include __DIR__ . "/adminer/include/pdo.inc.php";
 include __DIR__ . "/adminer/include/driver.inc.php";
 $connection = (object) array('flavor' => ''); // used in support()
index ea25c2b0970b07bb78d37065ef975a454be93333..d6a2399ab0e8ebd474f4eacd5cbecd9a771f3f5c 100644 (file)
@@ -12,17 +12,22 @@ parameters:
                - identifier: include.fileNotFound # relative includes
                - identifier: includeOnce.fileNotFound # ./adminer-plugins.php
                - "~^Function (set_magic_quotes_runtime|mysql_)~" # PHP < 7 functions
-               - "~^Function (foreign_keys_sql|recreate_table) not found~" # defined by other drivers
+               - "~an unknown class OCI-?Lob~" # this looks like PHPStan bug
                - "~^Variable \\$(adminer|connection|driver|drivers|error|HTTPS|LANG|langs|permanent|has_token|token|translations|VERSION) might not be defined~" # declared in bootstrap.inc.php
                - "~^Method Adminer\\\\Plugins::\\w+\\(\\) with return type void~" # we use the same pattern for all methods
                - "~Call to function is_object\\(\\) with Adminer\\\\Db\\|string will always evaluate to false~" # is_object(Db) is true
                - "~^Comparison operation \"==\" between \\(array\\|float\\|int\\) and 1~" # it thinks that $affected could be an array
-               - "~^Parameter #2 \\$newvalue of function ini_set expects string~" # it expects string|int|float|bool|null
+               - "~^Parameter #2 \\$newvalue of function ini_set expects string~" # it expects string|int|float|bool|null since PHP 8.1
                - "~expects int, float given~" # this will work
                - "~expects bool~" # truthy values
                - "~fread expects int<1, max>, 100000~" # 1e6
                - "~'strlen' given~" # used as a bool callback
-               - "~Adminer\\\\(Db|PdoDb).* type specified~" # duplicate methods
+
+               -
+                       message: "~ type specified~" # duplicate functions and methods
+                       paths:
+                               - adminer/include/pdo.inc.php
+                               - adminer/drivers/*
 
                # it probably doesn't like $ar[$key] instead of isset($ar[$key]) and thinks that $ar[$key] is always set
                - identifier: identical.alwaysFalse
@@ -42,18 +47,16 @@ parameters:
                - identifier: deadCode.unreachable
 
        paths:
+               - adminer/drivers/mysql.inc.php # other drivers inherit the annotations so we take them from here
                - adminer/
        scanFiles:
                - compile.php # compile_file()
        excludePaths:
+               - adminer/lang/
                - adminer/adminer-plugins.php
                - adminer/designs.php
                - adminer/elastic.php
                - adminer/sqlite.php
-               - adminer/drivers/mssql.inc.php
-               - adminer/drivers/oracle.inc.php
-               - adminer/drivers/pgsql.inc.php
-               - adminer/drivers/sqlite.inc.php
 
        phpVersion:
                min: 70100
index bba1e160081faabf90ca6307613ed85ca9033ea2..bfecb509666fdf6ce0234650d5bba9a908c1c760 100644 (file)
@@ -7,10 +7,10 @@ if (isset($_GET["clickhouse"])) {
        define('Adminer\DRIVER', "clickhouse");
 
        if (ini_bool('allow_url_fopen')) {
-               class Db {
-                       public $extension = "JSON", $flavor = '', $server_info, $errno, $error;
+               class Db extends SqlDb {
+                       public $extension = "JSON";
                        public $_db = 'default';
-                       private $result, $url;
+                       private $url;
 
                        function rootQuery($db, $query) {
                                $file = @file_get_contents("$this->url/?database=$db", false, stream_context_create(array('http' => array(
@@ -52,7 +52,7 @@ if (isset($_GET["clickhouse"])) {
                                return (bool) preg_match('~^(select|show)~i', $query);
                        }
 
-                       function query($query) {
+                       function query($query, $unbuffered = false) {
                                return $this->rootQuery($this->_db, $query);
                        }
 
@@ -71,23 +71,6 @@ if (isset($_GET["clickhouse"])) {
                        function quote($string) {
                                return "'" . addcslashes($string, "\\'") . "'";
                        }
-
-                       function multi_query($query) {
-                               return $this->result = $this->query($query);
-                       }
-
-                       function store_result() {
-                               return $this->result;
-                       }
-
-                       function next_result() {
-                               return false;
-                       }
-
-                       function result($query, $field = 0) {
-                               $result = $this->query($query);
-                               return $result['data'];
-                       }
                }
 
                class Result {
index 7a6f332e629d994d5c081dfbbee64bbf092019e0..2db8d091ffd0710ebbed3e05b752d71ec54b3ebd 100644 (file)
@@ -8,8 +8,8 @@ if (isset($_GET["elastic"])) {
 
        if (ini_bool('allow_url_fopen')) {
 
-               class Db {
-                       public $extension = "JSON", $flavor = '', $server_info, $errno, $error;
+               class Db extends SqlDb {
+                       public $extension = "JSON";
                        private $url;
 
                        /**
@@ -65,7 +65,7 @@ if (isset($_GET["elastic"])) {
 
                                        $where = explode(" AND ", $matches[2]);
 
-                                       return $driver->select($matches[1], array("*"), $where, null, array(), $matches[3]);
+                                       return $driver->select($matches[1], array("*"), $where, array(), array(), $matches[3]);
                                }
 
                                return $this->rootQuery($path, $content, $method);
index 0bde0c75d6ad86da05502af02f8664d669c18320..4955a9cdfa03e58ef3870fb8d76f37c6858b9814 100644 (file)
@@ -11,17 +11,8 @@ if (isset($_GET["firebird"])) {
        define('Adminer\DRIVER', "firebird");
 
        if (extension_loaded("interbase")) {
-               class Db {
-                       public
-                               $extension = "Firebird",
-                               $flavor = '',
-                               $server_info,
-                               $affected_rows,
-                               $errno,
-                               $error,
-                               $_link
-                       ;
-                       private $result;
+               class Db extends SqlDb {
+                       public $extension = "Firebird", $_link;
 
                        function connect($server, $username, $password) {
                                $this->_link = ibase_connect($server, $username, $password);
@@ -45,7 +36,7 @@ if (isset($_GET["firebird"])) {
                        }
 
                        function query($query, $unbuffered = false) {
-                               $result = ibase_query($query, $this->_link);
+                               $result = ibase_query($this->_link, $query);
                                if (!$result) {
                                        $this->errno = ibase_errcode();
                                        $this->error = ibase_errmsg();
@@ -58,27 +49,6 @@ if (isset($_GET["firebird"])) {
                                }
                                return new Result($result);
                        }
-
-                       function multi_query($query) {
-                               return $this->result = $this->query($query);
-                       }
-
-                       function store_result() {
-                               return $this->result;
-                       }
-
-                       function next_result() {
-                               return false;
-                       }
-
-                       function result($query, $field = 0) {
-                               $result = $this->query($query);
-                               if (!$result || !$result->num_rows) {
-                                       return false;
-                               }
-                               $row = $result->fetch_row();
-                               return $row[$field];
-                       }
                }
 
                class Result {
index ad6f3c0257a30909e6495bd3b9c7cc48c8f4d862..af313767830fa06dd770aca4c75ac25c40ef7407 100644 (file)
@@ -18,10 +18,8 @@ if (isset($_GET["imap"])) {
        define('Adminer\DRIVER', "imap");
 
        if (extension_loaded("imap")) {
-               class Db {
+               class Db extends SqlDb {
                        public $extension = "IMAP";
-                       public $flavor = '';
-                       public $error;
                        public $server_info = "?"; // imap_mailboxmsginfo() or imap_check() don't return anything useful
                        private $mailbox;
                        private $imap;
index f36f6adc4f9ba05d8009a382577845a9eaff9e97..d4b56afa64e297f4293bd6fb395438bb629f2241 100644 (file)
@@ -7,8 +7,8 @@ if (isset($_GET["mongo"])) {
        define('Adminer\DRIVER', "mongo");
 
        if (class_exists('MongoDB\Driver\Manager')) {
-               class Db {
-                       public $extension = "MongoDB", $flavor = '', $server_info = MONGODB_VERSION, $affected_rows, $error, $last_id;
+               class Db extends SqlDb {
+                       public $extension = "MongoDB", $server_info = MONGODB_VERSION, $last_id;
                        /** @var \MongoDB\Driver\Manager */
                        public $_link;
                        public $_db, $_db_name;
@@ -42,7 +42,7 @@ if (isset($_GET["mongo"])) {
                                }
                        }
 
-                       function query($query) {
+                       function query($query, $unbuffered = false) {
                                return false;
                        }
 
@@ -170,7 +170,7 @@ if (isset($_GET["mongo"])) {
                        $driver = driver();
                        $fields = fields_from_edit();
                        if (!$fields) {
-                               $result = $driver->select($table, array("*"), null, null, array(), 10);
+                               $result = $driver->select($table, array("*"), array(), array(), array(), 10);
                                if ($result) {
                                        while ($row = $result->fetch_assoc()) {
                                                foreach ($row as $key => $val) {
index ead12be80d76008cff522f24ed93ee745fe54dc2..d1b660dd838bde0161237989f1c1d72b3af52ca1 100644 (file)
@@ -7,9 +7,8 @@ if (isset($_GET["simpledb"])) {
        define('Adminer\DRIVER', "simpledb");
 
        if (class_exists('SimpleXMLElement') && ini_bool('allow_url_fopen')) {
-               class Db {
-                       public $extension = "SimpleXML", $flavor = '', $server_info = '2009-04-15', $error, $timeout, $next, $affected_rows;
-                       private $result;
+               class Db extends SqlDb {
+                       public $extension = "SimpleXML", $server_info = '2009-04-15', $timeout, $next;
 
                        function select_db($database) {
                                return ($database == "domain");
@@ -38,18 +37,6 @@ if (isset($_GET["simpledb"])) {
                                return new Result($result);
                        }
 
-                       function multi_query($query) {
-                               return $this->result = $this->query($query);
-                       }
-
-                       function store_result() {
-                               return $this->result;
-                       }
-
-                       function next_result() {
-                               return false;
-                       }
-
                        function quote($string) {
                                return "'" . str_replace("'", "''", $string) . "'";
                        }