diff --git a/adminer/check.inc.php b/adminer/check.inc.php index 05989ed6..c0c12341 100644 --- a/adminer/check.inc.php +++ b/adminer/check.inc.php @@ -24,7 +24,7 @@ if ($row && !$error) { page_header(($name != "" ? lang('Alter check') . ": " . h($name) : lang('Create check')), $error, array("table" => $TABLE)); if (!$row) { - $checks = $driver->checkConstraints($TABLE); + $checks = driver()->checkConstraints($TABLE); $row = array("name" => $name, "clause" => $checks[$name]); } ?> diff --git a/adminer/create.inc.php b/adminer/create.inc.php index 6ef46f4a..f7ae98e3 100644 --- a/adminer/create.inc.php +++ b/adminer/create.inc.php @@ -140,7 +140,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { page_header(($TABLE != "" ? lang('Alter table') : lang('Create table')), $error, array("table" => $TABLE), h($TABLE)); if (!$_POST) { - $types = $driver->types(); + $types = driver()->types(); $row = array( "Engine" => $_COOKIE["adminer_engine"], "fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")), "on_update" => "")), @@ -171,7 +171,7 @@ $collations = collations(); if (is_array(reset($collations))) { $collations = call_user_func_array('array_merge', array_values($collations)); } -$engines = $driver->engines(); +$engines = driver()->engines(); // case of engine may differ foreach ($engines as $engine) { if (!strcasecmp($engine, $row["Engine"])) { diff --git a/adminer/db.inc.php b/adminer/db.inc.php index 93554519..39e5e499 100644 --- a/adminer/db.inc.php +++ b/adminer/db.inc.php @@ -69,7 +69,7 @@ if (adminer()->homepage()) { echo " \n"; echo "\n"; if ($_POST["search"] && $_POST["query"] != "") { - $_GET["where"][0]["op"] = $driver->convertOperator("LIKE %%"); + $_GET["where"][0]["op"] = driver()->convertOperator("LIKE %%"); search_tables(); } } diff --git a/adminer/download.inc.php b/adminer/download.inc.php index c9f7ddab..e2a8b5ec 100644 --- a/adminer/download.inc.php +++ b/adminer/download.inc.php @@ -6,7 +6,7 @@ $fields = fields($TABLE); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=" . friendly_url("$TABLE-" . implode("_", $_GET["where"])) . "." . friendly_url($_GET["field"])); $select = array(idf_escape($_GET["field"])); -$result = $driver->select($TABLE, $select, array(where($_GET, $fields)), $select); +$result = driver()->select($TABLE, $select, array(where($_GET, $fields)), $select); $row = ($result ? $result->fetch_row() : array()); -echo $driver->value($row[0], $fields[$_GET["field"]]); +echo driver()->value($row[0], $fields[$_GET["field"]]); exit; // don't output footer diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index 63adc3b6..90a4778d 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -640,7 +640,6 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row } function create_sql($table, $auto_increment, $style) { - global $driver; if (is_view(table_status1($table))) { $view = view($table); return "CREATE VIEW " . table($table) . " AS $view[select]"; @@ -664,7 +663,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row $fields[] = ($index["type"] == "INDEX" ? "INDEX $name" : "CONSTRAINT $name " . ($index["type"] == "UNIQUE" ? "UNIQUE" : "PRIMARY KEY")) . " (" . implode(", ", $columns) . ")"; } } - foreach ($driver->checkConstraints($table) as $name => $check) { + foreach (driver()->checkConstraints($table) as $name => $check) { $fields[] = "CONSTRAINT " . idf_escape($name) . " CHECK ($check)"; } return "CREATE TABLE " . table($table) . " (\n\t" . implode(",\n\t", $fields) . "\n)"; diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 0b252fdf..7c0a69c2 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -556,13 +556,12 @@ if (!defined('Adminer\DRIVER')) { * @return ForeignKey[] */ function foreign_keys(string $table): array { - global $driver; static $pattern = '(?:`(?:[^`]|``)+`|"(?:[^"]|"")+")'; $return = array(); $create_table = get_val("SHOW CREATE TABLE " . table($table), 1); if ($create_table) { preg_match_all( - "~CONSTRAINT ($pattern) FOREIGN KEY ?\\(((?:$pattern,? ?)+)\\) REFERENCES ($pattern)(?:\\.($pattern))? \\(((?:$pattern,? ?)+)\\)(?: ON DELETE ($driver->onActions))?(?: ON UPDATE ($driver->onActions))?~", + "~CONSTRAINT ($pattern) FOREIGN KEY ?\\(((?:$pattern,? ?)+)\\) REFERENCES ($pattern)(?:\\.($pattern))? \\(((?:$pattern,? ?)+)\\)(?: ON DELETE (driver()->onActions))?(?: ON UPDATE (driver()->onActions))?~", $create_table, $matches, PREG_SET_ORDER @@ -860,13 +859,12 @@ if (!defined('Adminer\DRIVER')) { * @return Routine */ function routine(string $name, string $type): array { - global $driver; $aliases = array("bool", "boolean", "integer", "double precision", "real", "dec", "numeric", "fixed", "national char", "national varchar"); $space = "(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)"; - $enum = $driver->enumLength; - $type_pattern = "((" . implode("|", array_merge(array_keys($driver->types()), $aliases)) . ")\\b(?:\\s*\\(((?:[^'\")]|$enum)++)\\))?" + $enum = driver()->enumLength; + $type_pattern = "((" . implode("|", array_merge(array_keys(driver()->types()), $aliases)) . ")\\b(?:\\s*\\(((?:[^'\")]|$enum)++)\\))?" . "\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?)(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s,]+)['\"]?)?"; - $pattern = "$space*(" . ($type == "FUNCTION" ? "" : $driver->inout) . ")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern"; + $pattern = "$space*(" . ($type == "FUNCTION" ? "" : driver()->inout) . ")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern"; $create = get_val("SHOW CREATE $type " . idf_escape($name), 2); preg_match("~\\(((?:$pattern\\s*,?)*)\\)\\s*" . ($type == "FUNCTION" ? "RETURNS\\s+$type_pattern\\s+" : "") . "(.*)~is", $create, $match); $fields = array(); diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index d4d0ff42..0795ecf7 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -484,7 +484,6 @@ ORDER BY indisprimary DESC, indisunique DESC", $connection2) as $row } function foreign_keys($table) { - global $driver; $return = array(); foreach ( get_rows("SELECT conname, condeferrable::int AS deferrable, pg_get_constraintdef(oid) AS definition @@ -500,8 +499,8 @@ ORDER BY conkey, conname") as $row $row['table'] = idf_unescape($match2[4]); } $row['target'] = array_map('Adminer\idf_unescape', array_map('trim', explode(',', $match[3]))); - $row['on_delete'] = (preg_match("~ON DELETE ($driver->onActions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION'); - $row['on_update'] = (preg_match("~ON UPDATE ($driver->onActions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION'); + $row['on_delete'] = (preg_match("~ON DELETE (driver()->onActions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION'); + $row['on_update'] = (preg_match("~ON UPDATE (driver()->onActions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION'); $return[$row['conname']] = $row; } } @@ -793,12 +792,12 @@ AND typelem = 0" } function set_schema($schema, $connection2 = null) { - global $connection, $driver; + global $connection; if (!$connection2) { $connection2 = $connection; } $return = $connection2->query("SET search_path TO " . idf_escape($schema)); - $driver->setUserTypes(types()); //! get types from current_schemas('t') + driver()->setUserTypes(types()); //! get types from current_schemas('t') return $return; } @@ -820,7 +819,6 @@ AND typelem = 0" } function create_sql($table, $auto_increment, $style) { - global $driver; $return_parts = array(); $sequences = array(); @@ -872,7 +870,7 @@ AND typelem = 0" } } - foreach ($driver->checkConstraints($table) as $conname => $consrc) { + foreach (driver()->checkConstraints($table) as $conname => $consrc) { $return_parts[] = "CONSTRAINT " . idf_escape($conname) . " CHECK $consrc"; } diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index e4f7324b..27891dec 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -459,7 +459,6 @@ if (isset($_GET["sqlite"])) { * @param string $add_check CHECK constraint to add */ function recreate_table(string $table, string $name, array $fields, array $originals, array $foreign, int $auto_increment = 0, $indexes = array(), string $drop_check = "", string $add_check = ""): bool { - global $driver; if ($table != "") { if (!$fields) { foreach (fields($table) as $key => $field) { @@ -524,7 +523,7 @@ if (isset($_GET["sqlite"])) { $changes[] = " " . implode($field); } $changes = array_merge($changes, array_filter($foreign)); - foreach ($driver->checkConstraints($table) as $check) { + foreach (driver()->checkConstraints($table) as $check) { if ($check != $drop_check) { $changes[] = " CHECK ($check)"; } diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index 247066d6..68925ed3 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -27,7 +27,7 @@ if ($_POST && !$error && !isset($_GET["select"])) { queries_redirect( $location, lang('Item has been deleted.'), - $driver->delete($TABLE, $query_where, !$unique_array) + driver()->delete($TABLE, $query_where, !$unique_array) ); } else { @@ -46,7 +46,7 @@ if ($_POST && !$error && !isset($_GET["select"])) { queries_redirect( $location, lang('Item has been updated.'), - $driver->update($TABLE, $set, $query_where, !$unique_array) + driver()->update($TABLE, $set, $query_where, !$unique_array) ); if (is_ajax()) { page_headers(); @@ -54,7 +54,7 @@ if ($_POST && !$error && !isset($_GET["select"])) { exit; } } else { - $result = $driver->insert($TABLE, $set); + $result = driver()->insert($TABLE, $set); $last_id = ($result ? last_id($result) : 0); queries_redirect($location, lang('Item%s has been inserted.', ($last_id ? " $last_id" : "")), $result); //! link } @@ -77,7 +77,7 @@ if ($_POST["save"]) { $select = array("*"); } if ($select) { - $result = $driver->select($TABLE, $select, array($where), $select, array(), (isset($_GET["select"]) ? 2 : 1)); + $result = driver()->select($TABLE, $select, array($where), $select, array(), (isset($_GET["select"]) ? 2 : 1)); if (!$result) { $error = error(); } else { @@ -94,10 +94,10 @@ if ($_POST["save"]) { if (!support("table") && !$fields) { // used by Mongo and SimpleDB if (!$where) { // insert - $result = $driver->select($TABLE, array("*"), $where, array("*")); + $result = driver()->select($TABLE, array("*"), $where, array("*")); $row = ($result ? $result->fetch_assoc() : false); if (!$row) { - $row = array($driver->primary => ""); + $row = array(driver()->primary => ""); } } if ($row) { @@ -105,7 +105,7 @@ if (!support("table") && !$fields) { // used by Mongo and SimpleDB if (!$where) { $row[$key] = null; } - $fields[$key] = array("field" => $key, "null" => ($key != $driver->primary), "auto_increment" => ($key == $driver->primary)); + $fields[$key] = array("field" => $key, "null" => ($key != driver()->primary), "auto_increment" => ($key == driver()->primary)); } } } diff --git a/adminer/foreign.inc.php b/adminer/foreign.inc.php index d0a55445..792c12e6 100644 --- a/adminer/foreign.inc.php +++ b/adminer/foreign.inc.php @@ -101,8 +101,8 @@ foreach ($row["source"] as $key => $val) { ?>
-: "") + explode("|", $driver->onActions), $row["on_delete"]); ?>
- : "") + explode("|", $driver->onActions), $row["on_update"]); ?>
+: "") + explode("|", driver()->onActions), $row["on_delete"]); ?>
+ : "") + explode("|", driver()->onActions), $row["on_update"]); ?>
"innodb-foreign-key-constraints.html",
'mariadb' => "foreign-keys/",
diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php
index a87900d8..0162a627 100644
--- a/adminer/include/adminer.inc.php
+++ b/adminer/include/adminer.inc.php
@@ -64,8 +64,7 @@ class Adminer {
* @return list ';
$links = array("select" => lang('Select data'));
if (support("table") || support("indexes")) {
@@ -197,7 +195,7 @@ class Adminer {
foreach ($links as $key => $val) {
echo " $val";
}
- echo doc_link(array(JUSH => $driver->tableHelp($name, $is_view)), "?");
+ echo doc_link(array(JUSH => driver()->tableHelp($name, $is_view)), "?");
echo "\n";
}
@@ -227,9 +225,8 @@ class Adminer {
* @param float $start start time of the query
*/
function selectQuery(string $query, float $start, bool $failed = false): string {
- global $driver;
$return = "\n";
echo "
\n";
- $structured_types = $driver->structuredTypes();
+ $structured_types = driver()->structuredTypes();
foreach ($fields as $field) {
echo "" . lang('Column') . " " . lang('Type') . (support("comment") ? " " . lang('Comment') : "") . " " . h($field["field"]);
$type = h($field["full_type"]);
@@ -357,7 +353,6 @@ class Adminer {
* @param string[] $columns selectable columns
*/
function selectColumnsPrint(array $select, array $columns): void {
- global $driver;
print_fieldset("select", lang('Select'), $select);
$i = 0;
$select[""] = array();
@@ -369,7 +364,7 @@ class Adminer {
$val["col"],
($key !== "" ? "selectFieldChange" : "selectAddRow")
);
- echo " > [[select_expressions], [group_expressions]]
*/
function selectColumnsProcess(array $columns, array $indexes): array {
- global $driver;
$select = array(); // select expressions, empty for *
$group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
foreach ((array) $_GET["columns"] as $key => $val) {
- if ($val["fun"] == "count" || ($val["col"] != "" && (!$val["fun"] || in_array($val["fun"], $driver->functions) || in_array($val["fun"], $driver->grouping)))) {
+ if ($val["fun"] == "count" || ($val["col"] != "" && (!$val["fun"] || in_array($val["fun"], driver()->functions) || in_array($val["fun"], driver()->grouping)))) {
$select[$key] = apply_sql_function($val["fun"], ($val["col"] != "" ? idf_escape($val["col"]) : "*"));
- if (!in_array($val["fun"], $driver->grouping)) {
+ if (!in_array($val["fun"], driver()->grouping)) {
$group[] = $select[$key];
}
}
@@ -527,7 +521,7 @@ class Adminer {
* @return list