mirror of
https://github.com/vrana/adminer.git
synced 2025-08-13 10:04:07 +02:00
Use common parent for Db
This commit is contained in:
@@ -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));
|
||||
|
@@ -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
|
||||
class Db extends SqlDb {
|
||||
/** @var resource */ private $link;
|
||||
|
||||
/** @var \mysqli */ private $link;
|
||||
/** @var Result */ private $result;
|
||||
|
||||
/** Connect to server
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
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) {
|
||||
|
@@ -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;
|
||||
|
@@ -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() {
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user