Rename get_dbh to connection

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1124 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2009-09-22 10:51:40 +00:00
parent 342c1dce3b
commit 64d616c0cc
28 changed files with 193 additions and 186 deletions

View file

@ -23,25 +23,25 @@ if (!$error && $_POST) {
$val = "''"; $val = "''";
} }
if (isset($out[$key])) { if (isset($out[$key])) {
$dbh->query("SET @" . idf_escape($field["field"]) . " = $val"); $connection->query("SET @" . idf_escape($field["field"]) . " = $val");
} }
} }
$call[] = (isset($out[$key]) ? "@" . idf_escape($field["field"]) : $val); $call[] = (isset($out[$key]) ? "@" . idf_escape($field["field"]) : $val);
} }
$result = $dbh->multi_query((isset($_GET["callf"]) ? "SELECT" : "CALL") . " " . idf_escape($PROCEDURE) . "(" . implode(", ", $call) . ")"); $result = $connection->multi_query((isset($_GET["callf"]) ? "SELECT" : "CALL") . " " . idf_escape($PROCEDURE) . "(" . implode(", ", $call) . ")");
if (!$result) { if (!$result) {
echo "<p class='error'>" . h($dbh->error) . "\n"; echo "<p class='error'>" . h($connection->error) . "\n";
} else { } else {
do { do {
$result = $dbh->store_result(); $result = $connection->store_result();
if (is_object($result)) { if (is_object($result)) {
select($result); select($result);
} else { } else {
echo "<p class='message'>" . lang('Routine has been called, %d row(s) affected.', $dbh->affected_rows) . "\n"; echo "<p class='message'>" . lang('Routine has been called, %d row(s) affected.', $connection->affected_rows) . "\n";
} }
} while ($dbh->next_result()); } while ($connection->next_result());
if ($out) { if ($out) {
select($dbh->query("SELECT " . implode(", ", $out))); select($connection->query("SELECT " . implode(", ", $out)));
} }
} }
} }

View file

@ -62,9 +62,9 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
$orig_field = next($orig_fields); $orig_field = next($orig_fields);
} }
} }
$status = "COMMENT=" . $dbh->quote($_POST["Comment"]) $status = "COMMENT=" . $connection->quote($_POST["Comment"])
. ($_POST["Engine"] && $_POST["Engine"] != $orig_status["Engine"] ? " ENGINE=" . $dbh->quote($_POST["Engine"]) : "") . ($_POST["Engine"] && $_POST["Engine"] != $orig_status["Engine"] ? " ENGINE=" . $connection->quote($_POST["Engine"]) : "")
. ($_POST["Collation"] && $_POST["Collation"] != $orig_status["Collation"] ? " COLLATE " . $dbh->quote($_POST["Collation"]) : "") . ($_POST["Collation"] && $_POST["Collation"] != $orig_status["Collation"] ? " COLLATE " . $connection->quote($_POST["Collation"]) : "")
. (strlen($_POST["auto_increment"]) ? " AUTO_INCREMENT=" . intval($_POST["auto_increment"]) : "") . (strlen($_POST["auto_increment"]) ? " AUTO_INCREMENT=" . intval($_POST["auto_increment"]) : "")
; ;
if (in_array($_POST["partition_by"], $partition_by)) { if (in_array($_POST["partition_by"], $partition_by)) {
@ -79,7 +79,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
? " (" . implode(",", $partitions) . "\n)" ? " (" . implode(",", $partitions) . "\n)"
: ($_POST["partitions"] ? " PARTITIONS " . intval($_POST["partitions"]) : "") : ($_POST["partitions"] ? " PARTITIONS " . intval($_POST["partitions"]) : "")
); );
} elseif ($dbh->server_info >= 5.1 && strlen($TABLE)) { } elseif ($connection->server_info >= 5.1 && strlen($TABLE)) {
$status .= "\nREMOVE PARTITIONING"; $status .= "\nREMOVE PARTITIONING";
} }
$location = ME . "table=" . urlencode($_POST["name"]); $location = ME . "table=" . urlencode($_POST["name"]);
@ -94,7 +94,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
page_header((strlen($TABLE) ? lang('Alter table') : lang('Create table')), $error, array("table" => $TABLE), $TABLE); page_header((strlen($TABLE) ? lang('Alter table') : lang('Create table')), $error, array("table" => $TABLE), $TABLE);
$engines = array(); $engines = array();
$result = $dbh->query("SHOW ENGINES"); $result = $connection->query("SHOW ENGINES");
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
if ($row["Support"] == "YES" || $row["Support"] == "DEFAULT") { if ($row["Support"] == "YES" || $row["Support"] == "DEFAULT") {
$engines[] = $row["Engine"]; $engines[] = $row["Engine"];
@ -123,13 +123,13 @@ if ($_POST) {
} }
$row["fields"][] = $field; $row["fields"][] = $field;
} }
if ($dbh->server_info >= 5.1) { if ($connection->server_info >= 5.1) {
$from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . $dbh->quote(DB) . " AND TABLE_NAME = " . $dbh->quote($TABLE); $from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . $connection->quote(DB) . " AND TABLE_NAME = " . $connection->quote($TABLE);
$result = $dbh->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1"); $result = $connection->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");
list($row["partition_by"], $row["partitions"], $row["partition"]) = $result->fetch_row(); list($row["partition_by"], $row["partitions"], $row["partition"]) = $result->fetch_row();
$row["partition_names"] = array(); $row["partition_names"] = array();
$row["partition_values"] = array(); $row["partition_values"] = array();
$result = $dbh->query("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $from AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION"); $result = $connection->query("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $from AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION");
while ($row1 = $result->fetch_assoc()) { while ($row1 = $result->fetch_assoc()) {
$row["partition_names"][] = $row1["PARTITION_NAME"]; $row["partition_names"][] = $row1["PARTITION_NAME"];
$row["partition_values"][] = $row1["PARTITION_DESCRIPTION"]; $row["partition_values"][] = $row1["PARTITION_DESCRIPTION"];
@ -173,7 +173,7 @@ document.write('<label><input type="checkbox"<?php if ($column_comments) { ?> ch
<input type="hidden" name="token" value="<?php echo $token; ?>"> <input type="hidden" name="token" value="<?php echo $token; ?>">
<input type="submit" value="<?php echo lang('Save'); ?>"> <input type="submit" value="<?php echo lang('Save'); ?>">
<?php <?php
if ($dbh->server_info >= 5.1) { if ($connection->server_info >= 5.1) {
$partition_table = ereg('RANGE|LIST', $row["partition_by"]); $partition_table = ereg('RANGE|LIST', $row["partition_by"]);
?> ?>
<fieldset><legend><?php echo lang('Partition by'); ?></legend> <fieldset><legend><?php echo lang('Partition by'); ?></legend>

View file

@ -11,14 +11,14 @@ if ($_POST && !$error && !isset($_POST["add_x"])) { // add is an image and PHP c
$last = ""; $last = "";
foreach ($dbs as $db) { foreach ($dbs as $db) {
if (count($dbs) == 1 || strlen($db)) { // ignore empty lines but always try to create single database if (count($dbs) == 1 || strlen($db)) { // ignore empty lines but always try to create single database
if (!queries("CREATE DATABASE " . idf_escape($db) . ($_POST["collation"] ? " COLLATE " . $dbh->quote($_POST["collation"]) : ""))) { if (!queries("CREATE DATABASE " . idf_escape($db) . ($_POST["collation"] ? " COLLATE " . $connection->quote($_POST["collation"]) : ""))) {
$failed = true; $failed = true;
} }
$last = $db; $last = $db;
} }
} }
if (query_redirect(queries(), ME . "db=" . urlencode($last), lang('Database has been created.'), !strlen(DB), false, $failed)) { if (query_redirect(queries(), ME . "db=" . urlencode($last), lang('Database has been created.'), !strlen(DB), false, $failed)) {
$result = $dbh->query("SHOW TABLES"); $result = $connection->query("SHOW TABLES");
while ($row = $result->fetch_row()) { while ($row = $result->fetch_row()) {
if (!queries("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) { if (!queries("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) {
break; break;
@ -34,7 +34,7 @@ if ($_POST && !$error && !isset($_POST["add_x"])) { // add is an image and PHP c
if (!$_POST["collation"]) { if (!$_POST["collation"]) {
redirect(substr(ME, 0, -1)); redirect(substr(ME, 0, -1));
} }
query_redirect("ALTER DATABASE " . idf_escape($_POST["name"]) . " COLLATE " . $dbh->quote($_POST["collation"]), substr(ME, 0, -1), lang('Database has been altered.')); query_redirect("ALTER DATABASE " . idf_escape($_POST["name"]) . " COLLATE " . $connection->quote($_POST["collation"]), substr(ME, 0, -1), lang('Database has been altered.'));
} }
} }
@ -48,15 +48,15 @@ if ($_POST) {
$collate = $_POST["collation"]; $collate = $_POST["collation"];
} elseif (!strlen(DB)) { } elseif (!strlen(DB)) {
// propose database name with limited privileges // propose database name with limited privileges
$result = $dbh->query("SHOW GRANTS"); $result = $connection->query("SHOW GRANTS");
while ($row = $result->fetch_row()) { while ($row = $result->fetch_row()) {
if (preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~', $row[0], $match) && $match[1]) { if (preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~', $row[0], $match) && $match[1]) {
$name = stripcslashes(idf_unescape($match[2])); $name = stripcslashes(idf_unescape($match[2]));
break; break;
} }
} }
} elseif (($result = $dbh->query("SHOW CREATE DATABASE " . idf_escape(DB)))) { } elseif (($result = $connection->query("SHOW CREATE DATABASE " . idf_escape(DB)))) {
$create = $dbh->result($result, 1); $create = $connection->result($result, 1);
if (preg_match('~ COLLATE ([^ ]+)~', $create, $match)) { if (preg_match('~ COLLATE ([^ ]+)~', $create, $match)) {
$collate = $match[1]; $collate = $match[1];
} elseif (preg_match('~ CHARACTER SET ([^ ]+)~', $create, $match)) { } elseif (preg_match('~ CHARACTER SET ([^ ]+)~', $create, $match)) {

View file

@ -75,10 +75,10 @@ if (!$table_status) {
echo "</form>\n"; echo "</form>\n";
} }
if ($dbh->server_info >= 5) { if ($connection->server_info >= 5) {
echo '<p><a href="' . h(ME) . 'view=">' . lang('Create view') . "</a>\n"; echo '<p><a href="' . h(ME) . 'view=">' . lang('Create view') . "</a>\n";
echo "<h3>" . lang('Routines') . "</h3>\n"; echo "<h3>" . lang('Routines') . "</h3>\n";
$result = $dbh->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $dbh->quote(DB)); $result = $connection->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $connection->quote(DB));
if ($result->num_rows) { if ($result->num_rows) {
echo "<table cellspacing='0'>\n"; echo "<table cellspacing='0'>\n";
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
@ -92,7 +92,7 @@ if ($dbh->server_info >= 5) {
echo '<p><a href="' . h(ME) . 'procedure=">' . lang('Create procedure') . '</a> <a href="' . h(ME) . 'function=">' . lang('Create function') . "</a>\n"; echo '<p><a href="' . h(ME) . 'procedure=">' . lang('Create procedure') . '</a> <a href="' . h(ME) . 'function=">' . lang('Create function') . "</a>\n";
} }
if ($dbh->server_info >= 5.1 && ($result = $dbh->query("SHOW EVENTS"))) { if ($connection->server_info >= 5.1 && ($result = $connection->query("SHOW EVENTS"))) {
echo "<h3>" . lang('Events') . "</h3>\n"; echo "<h3>" . lang('Events') . "</h3>\n";
if ($result->num_rows) { if ($result->num_rows) {
echo "<table cellspacing='0'>\n"; echo "<table cellspacing='0'>\n";

View file

@ -2,5 +2,5 @@
$TABLE = $_GET["download"]; $TABLE = $_GET["download"];
header("Content-Type: application/octet-stream"); header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . friendly_url("$TABLE-" . implode("_", $_GET["where"])) . "." . friendly_url($_GET["field"])); header("Content-Disposition: attachment; filename=" . friendly_url("$TABLE-" . implode("_", $_GET["where"])) . "." . friendly_url($_GET["field"]));
echo $dbh->result($dbh->query("SELECT " . idf_escape($_GET["field"]) . " FROM " . idf_escape($TABLE) . " WHERE " . where($_GET) . " LIMIT 1")); echo $connection->result($connection->query("SELECT " . idf_escape($_GET["field"]) . " FROM " . idf_escape($TABLE) . " WHERE " . where($_GET) . " LIMIT 1"));
exit; // don't output footer exit; // don't output footer

View file

@ -7,7 +7,7 @@ if ($_POST) {
dump("-- Adminer $VERSION dump dump("-- Adminer $VERSION dump
SET NAMES utf8; SET NAMES utf8;
SET foreign_key_checks = 0; SET foreign_key_checks = 0;
SET time_zone = " . $dbh->quote($dbh->result($dbh->query("SELECT @@time_zone"))) . "; SET time_zone = " . $connection->quote($connection->result($connection->query("SELECT @@time_zone"))) . ";
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
"); ");
@ -15,31 +15,31 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
$style = $_POST["db_style"]; $style = $_POST["db_style"];
foreach ((strlen(DB) ? array(DB) : (array) $_POST["databases"]) as $db) { foreach ((strlen(DB) ? array(DB) : (array) $_POST["databases"]) as $db) {
if ($dbh->select_db($db)) { if ($connection->select_db($db)) {
if ($_POST["format"] == "sql" && ereg('CREATE', $style) && ($result = $dbh->query("SHOW CREATE DATABASE " . idf_escape($db)))) { if ($_POST["format"] == "sql" && ereg('CREATE', $style) && ($result = $connection->query("SHOW CREATE DATABASE " . idf_escape($db)))) {
if ($style == "DROP+CREATE") { if ($style == "DROP+CREATE") {
dump("DROP DATABASE IF EXISTS " . idf_escape($db) . ";\n"); dump("DROP DATABASE IF EXISTS " . idf_escape($db) . ";\n");
} }
$create = $dbh->result($result, 1); $create = $connection->result($result, 1);
dump(($style == "CREATE+ALTER" ? preg_replace('~^CREATE DATABASE ~', '\\0IF NOT EXISTS ', $create) : $create) . ";\n"); dump(($style == "CREATE+ALTER" ? preg_replace('~^CREATE DATABASE ~', '\\0IF NOT EXISTS ', $create) : $create) . ";\n");
} }
if ($style && $_POST["format"] == "sql") { if ($style && $_POST["format"] == "sql") {
dump("USE " . idf_escape($db) . ";\n" . ($style == "CREATE+ALTER" ? "SET @adminer_alter = '';\n" : "") . "\n"); dump("USE " . idf_escape($db) . ";\n" . ($style == "CREATE+ALTER" ? "SET @adminer_alter = '';\n" : "") . "\n");
$out = ""; $out = "";
if ($dbh->server_info >= 5) { if ($connection->server_info >= 5) {
foreach (array("FUNCTION", "PROCEDURE") as $routine) { foreach (array("FUNCTION", "PROCEDURE") as $routine) {
$result = $dbh->query("SHOW $routine STATUS WHERE Db = " . $dbh->quote($db)); $result = $connection->query("SHOW $routine STATUS WHERE Db = " . $connection->quote($db));
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$out .= ($style != 'DROP+CREATE' ? "DROP $routine IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") $out .= ($style != 'DROP+CREATE' ? "DROP $routine IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
. $dbh->result($dbh->query("SHOW CREATE $routine " . idf_escape($row["Name"])), 2) . ";;\n\n"; . $connection->result($connection->query("SHOW CREATE $routine " . idf_escape($row["Name"])), 2) . ";;\n\n";
} }
} }
} }
if ($dbh->server_info >= 5.1) { if ($connection->server_info >= 5.1) {
$result = $dbh->query("SHOW EVENTS"); $result = $connection->query("SHOW EVENTS");
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") $out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
. $dbh->result($dbh->query("SHOW CREATE EVENT " . idf_escape($row["Name"])), 3) . ";;\n\n"; . $connection->result($connection->query("SHOW CREATE EVENT " . idf_escape($row["Name"])), 3) . ";;\n\n";
} }
} }
if ($out) { if ($out) {
@ -97,11 +97,11 @@ CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
FETCH tables INTO _table_name, _engine, _table_collation, _table_comment; FETCH tables INTO _table_name, _engine, _table_collation, _table_comment;
IF NOT done THEN IF NOT done THEN
CASE _table_name"); CASE _table_name");
$result = $dbh->query($query); $result = $connection->query($query);
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$comment = $dbh->quote($row["ENGINE"] == "InnoDB" ? preg_replace('~(?:(.+); )?InnoDB free: .*~', '\\1', $row["TABLE_COMMENT"]) : $row["TABLE_COMMENT"]); $comment = $connection->quote($row["ENGINE"] == "InnoDB" ? preg_replace('~(?:(.+); )?InnoDB free: .*~', '\\1', $row["TABLE_COMMENT"]) : $row["TABLE_COMMENT"]);
dump(" dump("
WHEN " . $dbh->quote($row["TABLE_NAME"]) . " THEN WHEN " . $connection->quote($row["TABLE_NAME"]) . " THEN
" . (isset($row["ENGINE"]) ? "IF _engine != '$row[ENGINE]' OR _table_collation != '$row[TABLE_COLLATION]' OR _table_comment != $comment THEN " . (isset($row["ENGINE"]) ? "IF _engine != '$row[ENGINE]' OR _table_collation != '$row[TABLE_COLLATION]' OR _table_comment != $comment THEN
ALTER TABLE " . idf_escape($row["TABLE_NAME"]) . " ENGINE=$row[ENGINE] COLLATE=$row[TABLE_COLLATION] COMMENT=$comment; ALTER TABLE " . idf_escape($row["TABLE_NAME"]) . " ENGINE=$row[ENGINE] COLLATE=$row[TABLE_COLLATION] COMMENT=$comment;
END IF" : "BEGIN END") . ";"); END IF" : "BEGIN END") . ";");
@ -137,7 +137,7 @@ page_header(lang('Export'), "", (strlen($_GET["export"]) ? array("table" => $_GE
$db_style = array('', 'USE', 'DROP+CREATE', 'CREATE'); $db_style = array('', 'USE', 'DROP+CREATE', 'CREATE');
$table_style = array('', 'DROP+CREATE', 'CREATE'); $table_style = array('', 'DROP+CREATE', 'CREATE');
$data_style = array('', 'TRUNCATE+INSERT', 'INSERT', 'INSERT+UPDATE'); $data_style = array('', 'TRUNCATE+INSERT', 'INSERT', 'INSERT+UPDATE');
if ($dbh->server_info >= 5) { if ($connection->server_info >= 5) {
$db_style[] = 'CREATE+ALTER'; $db_style[] = 'CREATE+ALTER';
$table_style[] = 'CREATE+ALTER'; $table_style[] = 'CREATE+ALTER';
} }

View file

@ -56,7 +56,7 @@ if ($_POST["save"]) {
} }
$row = array(); $row = array();
if ($select) { if ($select) {
$result = $dbh->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($TABLE) . " WHERE $where " . (isset($_GET["select"]) ? "HAVING COUNT(*) = 1" : "LIMIT 1")); $result = $connection->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($TABLE) . " WHERE $where " . (isset($_GET["select"]) ? "HAVING COUNT(*) = 1" : "LIMIT 1"));
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
} }
} }

View file

@ -8,17 +8,17 @@ if ($_POST && !$error) {
query_redirect("DROP EVENT " . idf_escape($EVENT), substr(ME, 0, -1), lang('Event has been dropped.')); query_redirect("DROP EVENT " . idf_escape($EVENT), substr(ME, 0, -1), lang('Event has been dropped.'));
} elseif (in_array($_POST["INTERVAL_FIELD"], $intervals) && isset($statuses[$_POST["STATUS"]])) { } elseif (in_array($_POST["INTERVAL_FIELD"], $intervals) && isset($statuses[$_POST["STATUS"]])) {
$schedule = "\nON SCHEDULE " . ($_POST["INTERVAL_VALUE"] $schedule = "\nON SCHEDULE " . ($_POST["INTERVAL_VALUE"]
? "EVERY " . $dbh->quote($_POST["INTERVAL_VALUE"]) . " $_POST[INTERVAL_FIELD]" ? "EVERY " . $connection->quote($_POST["INTERVAL_VALUE"]) . " $_POST[INTERVAL_FIELD]"
. ($_POST["STARTS"] ? " STARTS " . $dbh->quote($_POST["STARTS"]) : "") . ($_POST["STARTS"] ? " STARTS " . $connection->quote($_POST["STARTS"]) : "")
. ($_POST["ENDS"] ? " ENDS " . $dbh->quote($_POST["ENDS"]) : "") //! ALTER EVENT doesn't drop ENDS - MySQL bug #39173 . ($_POST["ENDS"] ? " ENDS " . $connection->quote($_POST["ENDS"]) : "") //! ALTER EVENT doesn't drop ENDS - MySQL bug #39173
: "AT " . $dbh->quote($_POST["STARTS"]) : "AT " . $connection->quote($_POST["STARTS"])
) . " ON COMPLETION" . ($_POST["ON_COMPLETION"] ? "" : " NOT") . " PRESERVE" ) . " ON COMPLETION" . ($_POST["ON_COMPLETION"] ? "" : " NOT") . " PRESERVE"
; ;
query_redirect((strlen($EVENT) query_redirect((strlen($EVENT)
? "ALTER EVENT " . idf_escape($EVENT) . $schedule ? "ALTER EVENT " . idf_escape($EVENT) . $schedule
. ($EVENT != $_POST["EVENT_NAME"] ? "\nRENAME TO " . idf_escape($_POST["EVENT_NAME"]) : "") . ($EVENT != $_POST["EVENT_NAME"] ? "\nRENAME TO " . idf_escape($_POST["EVENT_NAME"]) : "")
: "CREATE EVENT " . idf_escape($_POST["EVENT_NAME"]) . $schedule : "CREATE EVENT " . idf_escape($_POST["EVENT_NAME"]) . $schedule
) . "\n" . $statuses[$_POST["STATUS"]] . " COMMENT " . $dbh->quote($_POST["EVENT_COMMENT"]) ) . "\n" . $statuses[$_POST["STATUS"]] . " COMMENT " . $connection->quote($_POST["EVENT_COMMENT"])
. " DO\n$_POST[EVENT_DEFINITION]" . " DO\n$_POST[EVENT_DEFINITION]"
, substr(ME, 0, -1), (strlen($EVENT) ? lang('Event has been altered.') : lang('Event has been created.'))); , substr(ME, 0, -1), (strlen($EVENT) ? lang('Event has been altered.') : lang('Event has been created.')));
} }
@ -30,7 +30,7 @@ $row = array();
if ($_POST) { if ($_POST) {
$row = $_POST; $row = $_POST;
} elseif (strlen($EVENT)) { } elseif (strlen($EVENT)) {
$result = $dbh->query("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = " . $dbh->quote(DB) . " AND EVENT_NAME = " . $dbh->quote($EVENT)); $result = $connection->query("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = " . $connection->quote(DB) . " AND EVENT_NAME = " . $connection->quote($EVENT));
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
} }
?> ?>

View file

@ -278,11 +278,11 @@ class Adminer {
* @return array expressions to join by AND * @return array expressions to join by AND
*/ */
function selectSearchProcess($fields, $indexes) { function selectSearchProcess($fields, $indexes) {
global $dbh; global $connection;
$return = array(); $return = array();
foreach ($indexes as $i => $index) { foreach ($indexes as $i => $index) {
if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) { if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) {
$return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . $dbh->quote($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")"; $return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . $connection->quote($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
} }
} }
foreach ((array) $_GET["where"] as $val) { foreach ((array) $_GET["where"] as $val) {
@ -404,9 +404,9 @@ class Adminer {
* @return string expression to use in a query * @return string expression to use in a query
*/ */
function processInput($field, $value, $function = "") { function processInput($field, $value, $function = "") {
global $dbh; global $connection;
$name = $field["field"]; $name = $field["field"];
$return = $dbh->quote($value); $return = $connection->quote($value);
if (ereg('^(now|uuid)$', $function)) { if (ereg('^(now|uuid)$', $function)) {
$return = "$function()"; $return = "$function()";
} elseif (ereg('^[+-]$', $function)) { } elseif (ereg('^[+-]$', $function)) {
@ -470,9 +470,9 @@ class Adminer {
* @return null * @return null
*/ */
function printTables($missing) { function printTables($missing) {
global $dbh; global $connection;
if ($missing != "db" && strlen(DB) && $dbh->select_db(DB)) { if ($missing != "db" && strlen(DB) && $connection->select_db(DB)) {
$result = $dbh->query("SHOW TABLES"); $result = $connection->query("SHOW TABLES");
if (!$result->num_rows) { if (!$result->num_rows) {
echo "<p class='message'>" . lang('No tables.') . "\n"; echo "<p class='message'>" . lang('No tables.') . "\n";
} else { } else {

View file

@ -31,10 +31,10 @@ if (isset($_POST["server"])) {
} }
function auth_error($exception = null) { function auth_error($exception = null) {
global $ignore, $dbh, $adminer; global $ignore, $connection, $adminer;
$username = $_SESSION["usernames"][$_GET["server"]]; $username = $_SESSION["usernames"][$_GET["server"]];
unset($_SESSION["usernames"][$_GET["server"]]); unset($_SESSION["usernames"][$_GET["server"]]);
page_header(lang('Login'), (isset($username) ? h($exception ? $exception->getMessage() : (is_string($dbh) ? $dbh : lang('Invalid credentials.'))) : (isset($_POST["server"]) ? lang('Session support must be enabled.') : ($_POST ? lang('Session expired, please login again.') : ""))), null); page_header(lang('Login'), (isset($username) ? h($exception ? $exception->getMessage() : (is_string($connection) ? $connection : lang('Invalid credentials.'))) : (isset($_POST["server"]) ? lang('Session support must be enabled.') : ($_POST ? lang('Session expired, please login again.') : ""))), null);
echo "<form action='' method='post'>\n"; echo "<form action='' method='post'>\n";
$adminer->loginForm($username); $adminer->loginForm($username);
echo "<p>\n"; echo "<p>\n";
@ -50,8 +50,8 @@ $username = &$_SESSION["usernames"][$_GET["server"]];
if (!isset($username)) { if (!isset($username)) {
$username = $_GET["username"]; // default username can be passed in URL $username = $_GET["username"]; // default username can be passed in URL
} }
$dbh = (isset($username) ? connect() : ''); $connection = (isset($username) ? connect() : '');
if (is_string($dbh) || !$adminer->login($username, $_SESSION["passwords"][$_GET["server"]])) { if (is_string($connection) || !$adminer->login($username, $_SESSION["passwords"][$_GET["server"]])) {
auth_error(); auth_error();
exit; exit;
} }

View file

@ -1,6 +1,6 @@
<?php <?php
function connect_error() { function connect_error() {
global $dbh, $VERSION; global $connection, $VERSION;
if (strlen(DB)) { if (strlen(DB)) {
page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), false); page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), false);
} else { } else {
@ -13,13 +13,13 @@ function connect_error() {
) as $key => $val) { ) as $key => $val) {
echo "<p><a href='" . h(ME) . "$key='>$val</a>\n"; echo "<p><a href='" . h(ME) . "$key='>$val</a>\n";
} }
echo "<p>" . lang('MySQL version: %s through PHP extension %s', "<b" . ($dbh->server_info < 4.1 ? " class='binary'" : "") . ">$dbh->server_info</b>", "<b>$dbh->extension</b>") . "\n"; echo "<p>" . lang('MySQL version: %s through PHP extension %s', "<b" . ($connection->server_info < 4.1 ? " class='binary'" : "") . ">$connection->server_info</b>", "<b>$connection->extension</b>") . "\n";
echo "<p>" . lang('Logged as: %s', "<b>" . h($dbh->result($dbh->query("SELECT USER()"))) . "</b>") . "\n"; echo "<p>" . lang('Logged as: %s', "<b>" . h($connection->result($connection->query("SELECT USER()"))) . "</b>") . "\n";
} }
page_footer("db"); page_footer("db");
} }
if (!(strlen(DB) ? $dbh->select_db(DB) : isset($_GET["sql"]) || isset($_GET["dump"]) || isset($_GET["database"]) || isset($_GET["processlist"]) || isset($_GET["privileges"]) || isset($_GET["user"]) || isset($_GET["variables"]))) { if (!(strlen(DB) ? $connection->select_db(DB) : isset($_GET["sql"]) || isset($_GET["dump"]) || isset($_GET["database"]) || isset($_GET["processlist"]) || isset($_GET["privileges"]) || isset($_GET["user"]) || isset($_GET["variables"]))) {
if (strlen(DB)) { if (strlen(DB)) {
unset($_SESSION["databases"][$_GET["server"]]); unset($_SESSION["databases"][$_GET["server"]]);
} }

View file

@ -4,7 +4,7 @@
* @param Min_DB connection to examine indexes * @param Min_DB connection to examine indexes
* @return null * @return null
*/ */
function select($result, $dbh2 = null) { function select($result, $connection2 = null) {
if (!$result->num_rows) { if (!$result->num_rows) {
echo "<p class='message'>" . lang('No rows.') . "\n"; echo "<p class='message'>" . lang('No rows.') . "\n";
} else { } else {
@ -24,7 +24,7 @@ function select($result, $dbh2 = null) {
if (!isset($indexes[$field->orgtable])) { if (!isset($indexes[$field->orgtable])) {
// find primary key in each table // find primary key in each table
$indexes[$field->orgtable] = array(); $indexes[$field->orgtable] = array();
foreach (indexes($field->orgtable, $dbh2) as $index) { foreach (indexes($field->orgtable, $connection2) as $index) {
if ($index["type"] == "PRIMARY") { if ($index["type"] == "PRIMARY") {
$indexes[$field->orgtable] = array_flip($index["columns"]); $indexes[$field->orgtable] = array_flip($index["columns"]);
break; break;
@ -112,21 +112,21 @@ function process_length($length) {
} }
function process_type($field, $collate = "COLLATE") { function process_type($field, $collate = "COLLATE") {
global $dbh, $enum_length, $unsigned; global $connection, $enum_length, $unsigned;
return " $field[type]" return " $field[type]"
. ($field["length"] && !ereg('^date|time$', $field["type"]) ? "(" . process_length($field["length"]) . ")" : "") . ($field["length"] && !ereg('^date|time$', $field["type"]) ? "(" . process_length($field["length"]) . ")" : "")
. (ereg('int|float|double|decimal', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "") . (ereg('int|float|double|decimal', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
. (ereg('char|text|enum|set', $field["type"]) && $field["collation"] ? " $collate " . $dbh->quote($field["collation"]) : "") . (ereg('char|text|enum|set', $field["type"]) && $field["collation"] ? " $collate " . $connection->quote($field["collation"]) : "")
; ;
} }
function process_field($field, $type_field) { function process_field($field, $type_field) {
global $dbh; global $connection;
$default = $field["default"] . ($field["on_update"] ? " ON UPDATE $field[on_update]" : ""); $default = $field["default"] . ($field["on_update"] ? " ON UPDATE $field[on_update]" : "");
return idf_escape($field["field"]) . process_type($type_field) return idf_escape($field["field"]) . process_type($type_field)
. ($field["null"] ? " NULL" : " NOT NULL") // NULL for timestamp . ($field["null"] ? " NULL" : " NOT NULL") // NULL for timestamp
. (!isset($field["default"]) || $field["auto_increment"] || ereg('text|blob', $field["type"]) ? "" : " DEFAULT " . ($field["type"] == "timestamp" && eregi("^CURRENT_TIMESTAMP( on update CURRENT_TIMESTAMP)?$", $default) ? $default : $dbh->quote($default))) . (!isset($field["default"]) || $field["auto_increment"] || ereg('text|blob', $field["type"]) ? "" : " DEFAULT " . ($field["type"] == "timestamp" && eregi("^CURRENT_TIMESTAMP( on update CURRENT_TIMESTAMP)?$", $default) ? $default : $connection->quote($default)))
. " COMMENT " . $dbh->quote($field["comment"]) . " COMMENT " . $connection->quote($field["comment"])
; ;
} }
@ -233,11 +233,11 @@ function normalize_enum($match) {
} }
function routine($name, $type) { function routine($name, $type) {
global $dbh, $enum_length, $inout, $types; global $connection, $enum_length, $inout, $types;
$aliases = array("bit" => "tinyint", "bool" => "tinyint", "boolean" => "tinyint", "integer" => "int", "double precision" => "float", "real" => "float", "dec" => "decimal", "numeric" => "decimal", "fixed" => "decimal", "national char" => "char", "national varchar" => "varchar"); $aliases = array("bit" => "tinyint", "bool" => "tinyint", "boolean" => "tinyint", "integer" => "int", "double precision" => "float", "real" => "float", "dec" => "decimal", "numeric" => "decimal", "fixed" => "decimal", "national char" => "char", "national varchar" => "varchar");
$type_pattern = "(" . implode("|", array_keys($types + $aliases)) . ")(?:\\s*\\(((?:[^'\")]*|$enum_length)+)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s]+)['\"]?)?"; $type_pattern = "(" . implode("|", array_keys($types + $aliases)) . ")(?:\\s*\\(((?:[^'\")]*|$enum_length)+)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s]+)['\"]?)?";
$pattern = "\\s*(" . ($type == "FUNCTION" ? "" : implode("|", $inout)) . ")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern"; $pattern = "\\s*(" . ($type == "FUNCTION" ? "" : implode("|", $inout)) . ")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern";
$create = $dbh->result($dbh->query("SHOW CREATE $type " . idf_escape($name)), 2); $create = $connection->result($connection->query("SHOW CREATE $type " . idf_escape($name)), 2);
preg_match("~\\(((?:$pattern\\s*,?)*)\\)" . ($type == "FUNCTION" ? "\\s*RETURNS\\s+$type_pattern" : "") . "\\s*(.*)~is", $create, $match); preg_match("~\\(((?:$pattern\\s*,?)*)\\)" . ($type == "FUNCTION" ? "\\s*RETURNS\\s+$type_pattern" : "") . "\\s*(.*)~is", $create, $match);
$fields = array(); $fields = array();
preg_match_all("~$pattern\\s*,?~is", $match[1], $matches, PREG_SET_ORDER); preg_match_all("~$pattern\\s*,?~is", $match[1], $matches, PREG_SET_ORDER);

View file

@ -10,9 +10,9 @@ function tar_file($filename, $contents) {
} }
function dump_triggers($table, $style) { function dump_triggers($table, $style) {
global $dbh; global $connection;
if ($_POST["format"] == "sql" && $style && $dbh->server_info >= 5) { if ($_POST["format"] == "sql" && $style && $connection->server_info >= 5) {
$result = $dbh->query("SHOW TRIGGERS LIKE " . $dbh->quote(addcslashes($table, "%_"))); $result = $connection->query("SHOW TRIGGERS LIKE " . $connection->quote(addcslashes($table, "%_")));
if ($result->num_rows) { if ($result->num_rows) {
$s = "\nDELIMITER ;;\n"; $s = "\nDELIMITER ;;\n";
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
@ -25,24 +25,24 @@ function dump_triggers($table, $style) {
} }
function dump_table($table, $style, $is_view = false) { function dump_table($table, $style, $is_view = false) {
global $dbh; global $connection;
if ($_POST["format"] == "csv") { if ($_POST["format"] == "csv") {
dump("\xef\xbb\xbf"); // UTF-8 byte order mark dump("\xef\xbb\xbf"); // UTF-8 byte order mark
if ($style) { if ($style) {
dump_csv(array_keys(fields($table))); dump_csv(array_keys(fields($table)));
} }
} elseif ($style) { } elseif ($style) {
$result = $dbh->query("SHOW CREATE TABLE " . idf_escape($table)); $result = $connection->query("SHOW CREATE TABLE " . idf_escape($table));
if ($result) { if ($result) {
if ($style == "DROP+CREATE") { if ($style == "DROP+CREATE") {
dump("DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . idf_escape($table) . ";\n"); dump("DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . idf_escape($table) . ";\n");
} }
$create = $dbh->result($result, 1); $create = $connection->result($result, 1);
dump(($style != "CREATE+ALTER" ? $create : ($is_view ? substr_replace($create, " OR REPLACE", 6, 0) : substr_replace($create, " IF NOT EXISTS", 12, 0))) . ";\n\n"); dump(($style != "CREATE+ALTER" ? $create : ($is_view ? substr_replace($create, " OR REPLACE", 6, 0) : substr_replace($create, " IF NOT EXISTS", 12, 0))) . ";\n\n");
} }
if ($style == "CREATE+ALTER" && !$is_view) { if ($style == "CREATE+ALTER" && !$is_view) {
// create procedure which iterates over original columns and adds new and removes old // create procedure which iterates over original columns and adds new and removes old
$query = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLLATION_NAME, COLUMN_TYPE, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = " . $dbh->quote($table) . " ORDER BY ORDINAL_POSITION"; $query = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLLATION_NAME, COLUMN_TYPE, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = " . $connection->quote($table) . " ORDER BY ORDINAL_POSITION";
dump("DELIMITER ;; dump("DELIMITER ;;
CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
DECLARE _column_name, _collation_name, _column_type, after varchar(64) DEFAULT ''; DECLARE _column_name, _collation_name, _column_type, after varchar(64) DEFAULT '';
@ -53,18 +53,18 @@ CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
DECLARE done, set_after bool DEFAULT 0; DECLARE done, set_after bool DEFAULT 0;
DECLARE add_columns text DEFAULT '"); DECLARE add_columns text DEFAULT '");
$fields = array(); $fields = array();
$result = $dbh->query($query); $result = $connection->query($query);
$after = ""; $after = "";
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$row["default"] = (isset($row["COLUMN_DEFAULT"]) ? $dbh->quote($row["COLUMN_DEFAULT"]) : "NULL"); $row["default"] = (isset($row["COLUMN_DEFAULT"]) ? $connection->quote($row["COLUMN_DEFAULT"]) : "NULL");
$row["after"] = $dbh->quote($after); //! rgt AFTER lft, lft AFTER id doesn't work $row["after"] = $connection->quote($after); //! rgt AFTER lft, lft AFTER id doesn't work
$row["alter"] = escape_string(idf_escape($row["COLUMN_NAME"]) $row["alter"] = escape_string(idf_escape($row["COLUMN_NAME"])
. " $row[COLUMN_TYPE]" . " $row[COLUMN_TYPE]"
. ($row["COLLATION_NAME"] ? " COLLATE $row[COLLATION_NAME]" : "") . ($row["COLLATION_NAME"] ? " COLLATE $row[COLLATION_NAME]" : "")
. (isset($row["COLUMN_DEFAULT"]) ? " DEFAULT $row[default]" : "") . (isset($row["COLUMN_DEFAULT"]) ? " DEFAULT $row[default]" : "")
. ($row["IS_NULLABLE"] == "YES" ? "" : " NOT NULL") . ($row["IS_NULLABLE"] == "YES" ? "" : " NOT NULL")
. ($row["EXTRA"] ? " $row[EXTRA]" : "") . ($row["EXTRA"] ? " $row[EXTRA]" : "")
. ($row["COLUMN_COMMENT"] ? " COMMENT " . $dbh->quote($row["COLUMN_COMMENT"]) : "") . ($row["COLUMN_COMMENT"] ? " COMMENT " . $connection->quote($row["COLUMN_COMMENT"]) : "")
. ($after ? " AFTER " . idf_escape($after) : " FIRST") . ($after ? " AFTER " . idf_escape($after) : " FIRST")
); );
dump(", ADD $row[alter]"); dump(", ADD $row[alter]");
@ -83,9 +83,9 @@ CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
CASE _column_name"); CASE _column_name");
foreach ($fields as $row) { foreach ($fields as $row) {
dump(" dump("
WHEN " . $dbh->quote($row["COLUMN_NAME"]) . " THEN WHEN " . $connection->quote($row["COLUMN_NAME"]) . " THEN
SET add_columns = REPLACE(add_columns, ', ADD $row[alter]', ''); SET add_columns = REPLACE(add_columns, ', ADD $row[alter]', '');
IF NOT (_column_default <=> $row[default]) OR _is_nullable != '$row[IS_NULLABLE]' OR _collation_name != '$row[COLLATION_NAME]' OR _column_type != '$row[COLUMN_TYPE]' OR _extra != '$row[EXTRA]' OR _column_comment != " . $dbh->quote($row["COLUMN_COMMENT"]) . " OR after != $row[after] THEN IF NOT (_column_default <=> $row[default]) OR _is_nullable != '$row[IS_NULLABLE]' OR _collation_name != '$row[COLLATION_NAME]' OR _column_type != '$row[COLUMN_TYPE]' OR _extra != '$row[EXTRA]' OR _column_comment != " . $connection->quote($row["COLUMN_COMMENT"]) . " OR after != $row[after] THEN
SET @alter_table = CONCAT(@alter_table, ', MODIFY $row[alter]'); SET @alter_table = CONCAT(@alter_table, ', MODIFY $row[alter]');
END IF;"); //! don't replace in comment END IF;"); //! don't replace in comment
} }
@ -115,13 +115,13 @@ DROP PROCEDURE adminer_alter;
} }
function dump_data($table, $style, $select = "") { function dump_data($table, $style, $select = "") {
global $dbh, $max_packet; global $connection, $max_packet;
if ($style) { if ($style) {
if ($_POST["format"] != "csv" && $style == "TRUNCATE+INSERT") { if ($_POST["format"] != "csv" && $style == "TRUNCATE+INSERT") {
dump("TRUNCATE " . idf_escape($table) . ";\n"); dump("TRUNCATE " . idf_escape($table) . ";\n");
} }
$fields = fields($table); $fields = fields($table);
$result = $dbh->query(($select ? $select : "SELECT * FROM " . idf_escape($table)), 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers, microtime $result = $connection->query(($select ? $select : "SELECT * FROM " . idf_escape($table)), 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers, microtime
if ($result) { if ($result) {
$insert = ""; $insert = "";
$buffer = ""; $buffer = "";
@ -133,7 +133,7 @@ function dump_data($table, $style, $select = "") {
$insert = "INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES"; $insert = "INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
} }
foreach ($row as $key => $val) { foreach ($row as $key => $val) {
$row[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : $dbh->quote($val)) : "NULL"); //! columns looking like functions $row[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : $connection->quote($val)) : "NULL"); //! columns looking like functions
} }
$s = implode(",\t", $row); $s = implode(",\t", $row);
if ($style == "INSERT+UPDATE") { if ($style == "INSERT+UPDATE") {

View file

@ -2,10 +2,10 @@
/** Get database connection /** Get database connection
* @return Min_DB * @return Min_DB
*/ */
function get_dbh() { function connection() {
// can be used in customization, $dbh is minified // can be used in customization, $connection is minified
global $dbh; global $connection;
return $dbh; return $connection;
} }
/** Escape database identifier /** Escape database identifier
@ -87,9 +87,9 @@ function optionlist($options, $selected = null, $use_keys = false) {
* @return array * @return array
*/ */
function get_vals($query, $column = 0) { function get_vals($query, $column = 0) {
global $dbh; global $connection;
$return = array(); $return = array();
$result = $dbh->query($query); $result = $connection->query($query);
if ($result) { if ($result) {
while ($row = $result->fetch_row()) { while ($row = $result->fetch_row()) {
$return[] = $row[$column]; $return[] = $row[$column];
@ -130,11 +130,11 @@ function unique_idf($row, $indexes) {
* @return string * @return string
*/ */
function where($where) { function where($where) {
global $dbh; global $connection;
$return = array(); $return = array();
foreach ((array) $where["where"] as $key => $val) { foreach ((array) $where["where"] as $key => $val) {
$key = bracket_escape($key, "back"); $key = bracket_escape($key, "back");
$return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " = BINARY " . $dbh->quote($val); //! enum and set, columns looking like functions $return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " = BINARY " . $connection->quote($val); //! enum and set, columns looking like functions
} }
foreach ((array) $where["null"] as $key) { foreach ((array) $where["null"] as $key) {
$key = bracket_escape($key, "back"); $key = bracket_escape($key, "back");
@ -194,16 +194,16 @@ function redirect($location, $message = null) {
* @return bool * @return bool
*/ */
function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) { function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
global $dbh, $error, $adminer; global $connection, $error, $adminer;
$sql = ""; $sql = "";
if ($query) { if ($query) {
$sql = $adminer->messageQuery($query); $sql = $adminer->messageQuery($query);
} }
if ($execute) { if ($execute) {
$failed = !$dbh->query($query); $failed = !$connection->query($query);
} }
if ($failed) { if ($failed) {
$error = h($dbh->error) . $sql; $error = h($connection->error) . $sql;
return false; return false;
} }
if ($redirect) { if ($redirect) {
@ -217,14 +217,14 @@ function query_redirect($query, $location, $message, $redirect = true, $execute
* @return Min_Result * @return Min_Result
*/ */
function queries($query = null) { function queries($query = null) {
global $dbh; global $connection;
static $queries = array(); static $queries = array();
if (!isset($query)) { if (!isset($query)) {
// return executed queries without parameter // return executed queries without parameter
return implode(";\n", $queries); return implode(";\n", $queries);
} }
$queries[] = $query; $queries[] = $query;
return $dbh->query($query); return $connection->query($query);
} }
/** Remove parameter from query string /** Remove parameter from query string
@ -413,7 +413,7 @@ function input($field, $value, $function) {
* @return string * @return string
*/ */
function process_input($field) { function process_input($field) {
global $dbh, $adminer; global $connection, $adminer;
$idf = bracket_escape($field["field"]); $idf = bracket_escape($field["field"]);
$function = $_POST["function"][$idf]; $function = $_POST["function"][$idf];
$value = $_POST["fields"][$idf]; $value = $_POST["fields"][$idf];
@ -430,7 +430,7 @@ function process_input($field) {
if (!is_string($file)) { if (!is_string($file)) {
return false; //! report errors return false; //! report errors
} }
return "_binary" . $dbh->quote($file); return "_binary" . $connection->quote($file);
} else { } else {
return $adminer->processInput($field, $value, $function); return $adminer->processInput($field, $value, $function);
} }

View file

@ -145,14 +145,14 @@ if (extension_loaded("mysqli")) {
*/ */
function connect() { function connect() {
global $adminer; global $adminer;
$dbh = new Min_DB; $connection = new Min_DB;
$credentials = $adminer->credentials(); $credentials = $adminer->credentials();
if ($dbh->connect($credentials[0], $credentials[1], $credentials[2])) { if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
$dbh->query("SET SQL_QUOTE_SHOW_CREATE=1"); $connection->query("SET SQL_QUOTE_SHOW_CREATE=1");
$dbh->query("SET NAMES utf8"); $connection->query("SET NAMES utf8");
return $dbh; return $connection;
} }
return $dbh->error; return $connection->error;
} }
/** Get cached list of databases /** Get cached list of databases
@ -177,9 +177,9 @@ function get_databases($flush = true) {
* @return array * @return array
*/ */
function table_status($name = "") { function table_status($name = "") {
global $dbh; global $connection;
$return = array(); $return = array();
$result = $dbh->query("SHOW TABLE STATUS" . (strlen($name) ? " LIKE " . $dbh->quote(addcslashes($name, "%_")) : "")); $result = $connection->query("SHOW TABLE STATUS" . (strlen($name) ? " LIKE " . $connection->quote(addcslashes($name, "%_")) : ""));
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
if ($row["Engine"] == "InnoDB") { if ($row["Engine"] == "InnoDB") {
// ignore internal comment, unnecessary since MySQL 5.1.21 // ignore internal comment, unnecessary since MySQL 5.1.21
@ -208,9 +208,9 @@ function table_status_referencable() {
* @return array array($name => array("field" => , "full_type" => , "type" => , "length" => , "unsigned" => , "default" => , "null" => , "auto_increment" => , "on_update" => , "collation" => , "privileges" => , "comment" => , "primary" => )) * @return array array($name => array("field" => , "full_type" => , "type" => , "length" => , "unsigned" => , "default" => , "null" => , "auto_increment" => , "on_update" => , "collation" => , "privileges" => , "comment" => , "primary" => ))
*/ */
function fields($table) { function fields($table) {
global $dbh; global $connection;
$return = array(); $return = array();
$result = $dbh->query("SHOW FULL COLUMNS FROM " . idf_escape($table)); $result = $connection->query("SHOW FULL COLUMNS FROM " . idf_escape($table));
if ($result) { if ($result) {
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
preg_match('~^([^( ]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match); preg_match('~^([^( ]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
@ -239,13 +239,13 @@ function fields($table) {
* @param string Min_DB to use * @param string Min_DB to use
* @return array array($key_name => array("type" => , "columns" => array(), "lengths" => array())) * @return array array($key_name => array("type" => , "columns" => array(), "lengths" => array()))
*/ */
function indexes($table, $dbh2 = null) { function indexes($table, $connection2 = null) {
global $dbh; global $connection;
if (!is_object($dbh2)) { // use the main connection if the separate connection is unavailable if (!is_object($connection2)) { // use the main connection if the separate connection is unavailable
$dbh2 = $dbh; $connection2 = $connection;
} }
$return = array(); $return = array();
$result = $dbh2->query("SHOW INDEX FROM " . idf_escape($table)); $result = $connection2->query("SHOW INDEX FROM " . idf_escape($table));
if ($result) { if ($result) {
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE"))); $return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
@ -261,12 +261,12 @@ function indexes($table, $dbh2 = null) {
* @return array array($name => array("db" => , "table" => , "source" => array(), "target" => array(), "on_delete" => , "on_update" => )) * @return array array($name => array("db" => , "table" => , "source" => array(), "target" => array(), "on_delete" => , "on_update" => ))
*/ */
function foreign_keys($table) { function foreign_keys($table) {
global $dbh, $on_actions; global $connection, $on_actions;
static $pattern = '(?:[^`]|``)+'; static $pattern = '(?:[^`]|``)+';
$return = array(); $return = array();
$result = $dbh->query("SHOW CREATE TABLE " . idf_escape($table)); $result = $connection->query("SHOW CREATE TABLE " . idf_escape($table));
if ($result) { if ($result) {
$create_table = $dbh->result($result, 1); $create_table = $connection->result($result, 1);
preg_match_all("~CONSTRAINT `($pattern)` FOREIGN KEY \\(((?:`$pattern`,? ?)+)\\) REFERENCES `($pattern)`(?:\\.`($pattern)`)? \\(((?:`$pattern`,? ?)+)\\)(?: ON DELETE (" . implode("|", $on_actions) . "))?(?: ON UPDATE (" . implode("|", $on_actions) . "))?~", $create_table, $matches, PREG_SET_ORDER); preg_match_all("~CONSTRAINT `($pattern)` FOREIGN KEY \\(((?:`$pattern`,? ?)+)\\) REFERENCES `($pattern)`(?:\\.`($pattern)`)? \\(((?:`$pattern`,? ?)+)\\)(?: ON DELETE (" . implode("|", $on_actions) . "))?(?: ON UPDATE (" . implode("|", $on_actions) . "))?~", $create_table, $matches, PREG_SET_ORDER);
foreach ($matches as $match) { foreach ($matches as $match) {
preg_match_all("~`($pattern)`~", $match[2], $source); preg_match_all("~`($pattern)`~", $match[2], $source);
@ -289,17 +289,17 @@ function foreign_keys($table) {
* @return array array("select" => ) * @return array array("select" => )
*/ */
function view($name) { function view($name) {
global $dbh; global $connection;
return array("select" => preg_replace('~^(?:[^`]|`[^`]*`)* AS ~U', '', $dbh->result($dbh->query("SHOW CREATE VIEW " . idf_escape($name)), 1))); return array("select" => preg_replace('~^(?:[^`]|`[^`]*`)* AS ~U', '', $connection->result($connection->query("SHOW CREATE VIEW " . idf_escape($name)), 1)));
} }
/** Get sorted grouped list of collations /** Get sorted grouped list of collations
* @return array * @return array
*/ */
function collations() { function collations() {
global $dbh; global $connection;
$return = array(); $return = array();
$result = $dbh->query("SHOW COLLATION"); $result = $connection->query("SHOW COLLATION");
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$return[$row["Charset"]][] = $row["Collation"]; $return[$row["Charset"]][] = $row["Collation"];
} }
@ -315,8 +315,8 @@ function collations() {
* @return string * @return string
*/ */
function escape_string($val) { function escape_string($val) {
global $dbh; global $connection;
return substr($dbh->quote($val), 1, -1); return substr($connection->quote($val), 1, -1);
} }
/** Find out if database is information_schema /** Find out if database is information_schema
@ -324,8 +324,8 @@ function escape_string($val) {
* @return bool * @return bool
*/ */
function information_schema($db) { function information_schema($db) {
global $dbh; global $connection;
return ($dbh->server_info >= 5 && $db == "information_schema"); return ($connection->server_info >= 5 && $db == "information_schema");
} }
// value means maximum unsigned length // value means maximum unsigned length

View file

@ -1,7 +1,7 @@
<?php <?php
page_header(lang('Privileges')); page_header(lang('Privileges'));
$result = $dbh->query("SELECT User, Host FROM mysql.user ORDER BY Host, User"); $result = $connection->query("SELECT User, Host FROM mysql.user ORDER BY Host, User");
if (!$result) { if (!$result) {
?> ?>
<form action=""><p> <form action=""><p>
@ -14,7 +14,7 @@ if (!$result) {
</form> </form>
<?php <?php
// list logged user, information_schema.USER_PRIVILEGES lists just the current user too // list logged user, information_schema.USER_PRIVILEGES lists just the current user too
$result = $dbh->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1) AS User, SUBSTRING_INDEX(CURRENT_USER, '@', -1) AS Host"); $result = $connection->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1) AS User, SUBSTRING_INDEX(CURRENT_USER, '@', -1) AS Host");
} }
echo "<table cellspacing='0'>\n"; echo "<table cellspacing='0'>\n";
echo "<thead><tr><th>&nbsp;<th>" . lang('Username') . "<th>" . lang('Server') . "</thead>\n"; echo "<thead><tr><th>&nbsp;<th>" . lang('Username') . "<th>" . lang('Server') . "</thead>\n";

View file

@ -15,7 +15,7 @@ page_header(lang('Process list'), $error);
<form action="" method="post"> <form action="" method="post">
<table cellspacing="0" onclick="table_click(event);"> <table cellspacing="0" onclick="table_click(event);">
<?php <?php
$result = $dbh->query("SHOW PROCESSLIST"); $result = $connection->query("SHOW PROCESSLIST");
for ($i=0; $row = $result->fetch_assoc(); $i++) { for ($i=0; $row = $result->fetch_assoc(); $i++) {
if (!$i) { if (!$i) {
echo "<thead><tr lang='en'><th>&nbsp;<th>" . implode("<th>", array_keys($row)) . "</thead>\n"; echo "<thead><tr lang='en'><th>&nbsp;<th>" . implode("<th>", array_keys($row)) . "</thead>\n";

View file

@ -74,7 +74,7 @@ if ($_POST && !$error) {
if ($_POST["delete"] || $set) { if ($_POST["delete"] || $set) {
if ($_POST["all"] || ($primary === array() && $_POST["check"])) { if ($_POST["all"] || ($primary === array() && $_POST["check"])) {
$result = queries($command . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check")); $result = queries($command . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check"));
$affected = $dbh->affected_rows; $affected = $connection->affected_rows;
} else { } else {
foreach ((array) $_POST["check"] as $val) { foreach ((array) $_POST["check"] as $val) {
// where is not unique so OR can't be used // where is not unique so OR can't be used
@ -82,7 +82,7 @@ if ($_POST && !$error) {
if (!$result) { if (!$result) {
break; break;
} }
$affected += $dbh->affected_rows; $affected += $connection->affected_rows;
} }
} }
} }
@ -103,7 +103,7 @@ if ($_POST && !$error) {
} else { } else {
$set = ""; $set = "";
foreach ($matches2[1] as $i => $col) { foreach ($matches2[1] as $i => $col) {
$set .= ", " . idf_escape($cols[$i]) . " = " . (!strlen($col) && $fields[$cols[$i]]["null"] ? "NULL" : $dbh->quote(str_replace('""', '"', preg_replace('~^"|"$~', '', $col)))); $set .= ", " . idf_escape($cols[$i]) . " = " . (!strlen($col) && $fields[$cols[$i]]["null"] ? "NULL" : $connection->quote(str_replace('""', '"', preg_replace('~^"|"$~', '', $col))));
} }
$set = substr($set, 1); $set = substr($set, 1);
$result = queries("INSERT INTO " . idf_escape($_GET["select"]) . " SET$set ON DUPLICATE KEY UPDATE$set"); $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . " SET$set ON DUPLICATE KEY UPDATE$set");
@ -136,7 +136,7 @@ if (isset($rights["insert"])) {
$adminer->selectLinks($table_status, $set); $adminer->selectLinks($table_status, $set);
if (!$columns) { if (!$columns) {
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . h($dbh->error)) . ".\n"; echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . h($connection->error)) . ".\n";
} else { } else {
echo "<form action='' id='form'>\n"; echo "<form action='' id='form'>\n";
echo "<div style='display: none;'>"; echo "<div style='display: none;'>";
@ -155,9 +155,9 @@ if (!$columns) {
$query = "SELECT " . (intval($limit) && $group && count($group) < count($select) ? "SQL_CALC_FOUND_ROWS " : "") . $from . $group_by . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : ""); $query = "SELECT " . (intval($limit) && $group && count($group) < count($select) ? "SQL_CALC_FOUND_ROWS " : "") . $from . $group_by . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : "");
echo $adminer->selectQuery($query); echo $adminer->selectQuery($query);
$result = $dbh->query($query); $result = $connection->query($query);
if (!$result) { if (!$result) {
echo "<p class='error'>" . h($dbh->error) . "\n"; echo "<p class='error'>" . h($connection->error) . "\n";
} else { } else {
$email_fields = array(); $email_fields = array();
echo "<form action='' method='post' enctype='multipart/form-data'>\n"; echo "<form action='' method='post' enctype='multipart/form-data'>\n";
@ -170,7 +170,7 @@ if (!$columns) {
} }
// use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest) // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
$found_rows = (intval($limit) && $group && count($group) < count($select) $found_rows = (intval($limit) && $group && count($group) < count($select)
? $dbh->result($dbh->query(" SELECT FOUND_ROWS()")) // space to allow mysql.trace_mode ? $connection->result($connection->query(" SELECT FOUND_ROWS()")) // space to allow mysql.trace_mode
: count($rows) : count($rows)
); );
@ -266,7 +266,7 @@ if (!$columns) {
// slow with big tables // slow with big tables
ob_flush(); ob_flush();
flush(); flush();
$found_rows = $dbh->result($dbh->query("SELECT COUNT(*) FROM " . idf_escape($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""))); $found_rows = $connection->result($connection->query("SELECT COUNT(*) FROM " . idf_escape($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : "")));
} }
echo "<p>"; echo "<p>";
if (intval($limit) && $found_rows > $limit) { if (intval($limit) && $found_rows > $limit) {

View file

@ -33,9 +33,9 @@ if (!$error && $_POST) {
$delimiter = ";"; $delimiter = ";";
$offset = 0; $offset = 0;
$empty = true; $empty = true;
$dbh2 = (strlen(DB) ? connect() : null); // connection for exploring indexes and EXPLAIN (to not replace FOUND_ROWS()) //! PDO - silent error $connection2 = (strlen(DB) ? connect() : null); // connection for exploring indexes and EXPLAIN (to not replace FOUND_ROWS()) //! PDO - silent error
if (is_object($dbh2)) { if (is_object($connection2)) {
$dbh2->select_db(DB); $connection2->select_db(DB);
} }
$explain = 1; $explain = 1;
while (strlen($query)) { while (strlen($query)) {
@ -60,8 +60,8 @@ if (!$error && $_POST) {
flush(); // can take a long time - show the running query flush(); // can take a long time - show the running query
$start = explode(" ", microtime()); // microtime(true) is available since PHP 5 $start = explode(" ", microtime()); // microtime(true) is available since PHP 5
//! don't allow changing of character_set_results, convert encoding of displayed query //! don't allow changing of character_set_results, convert encoding of displayed query
if (!$dbh->multi_query($q)) { if (!$connection->multi_query($q)) {
echo "<p class='error'>" . lang('Error in query') . ": " . h($dbh->error) . "\n"; echo "<p class='error'>" . lang('Error in query') . ": " . h($connection->error) . "\n";
if ($_POST["error_stops"]) { if ($_POST["error_stops"]) {
break; break;
} }
@ -69,15 +69,15 @@ if (!$error && $_POST) {
$end = explode(" ", microtime()); $end = explode(" ", microtime());
echo "<p class='time'>" . lang('%.3f s', max(0, $end[0] - $start[0] + $end[1] - $start[1])) . "</p>\n"; echo "<p class='time'>" . lang('%.3f s', max(0, $end[0] - $start[0] + $end[1] - $start[1])) . "</p>\n";
do { do {
$result = $dbh->store_result(); $result = $connection->store_result();
if (is_object($result)) { if (is_object($result)) {
select($result, $dbh2); select($result, $connection2);
echo "<p>" . lang('%d row(s)', $result->num_rows); echo "<p>" . lang('%d row(s)', $result->num_rows);
if ($dbh2 && preg_match("~^$space*SELECT$space+~isU", $q)) { if ($connection2 && preg_match("~^$space*SELECT$space+~isU", $q)) {
$id = "explain-$explain"; $id = "explain-$explain";
echo ", <a href='#$id' onclick=\"return !toggle('$id');\">EXPLAIN</a>\n"; echo ", <a href='#$id' onclick=\"return !toggle('$id');\">EXPLAIN</a>\n";
echo "<div id='$id' class='hidden'>\n"; echo "<div id='$id' class='hidden'>\n";
select($dbh2->query("EXPLAIN $q"), $dbh2); select($connection2->query("EXPLAIN $q"), $connection2);
echo "</div>\n"; echo "</div>\n";
$explain++; $explain++;
} }
@ -85,10 +85,10 @@ if (!$error && $_POST) {
if (preg_match("~^$space*$alter_database", $query)) { if (preg_match("~^$space*$alter_database", $query)) {
$databases = null; // clear cache $databases = null; // clear cache
} }
echo "<p class='message'>" . lang('Query executed OK, %d row(s) affected.', $dbh->affected_rows) . "\n"; echo "<p class='message'>" . lang('Query executed OK, %d row(s) affected.', $connection->affected_rows) . "\n";
} }
unset($result); // free resultset unset($result); // free resultset
} while ($dbh->next_result()); } while ($connection->next_result());
} }
$query = substr($query, $offset); $query = substr($query, $offset);
$offset = 0; $offset = 0;

View file

@ -1,8 +1,8 @@
<?php <?php
$TABLE = $_GET["table"]; $TABLE = $_GET["table"];
$result = $dbh->query("SHOW FULL COLUMNS FROM " . idf_escape($TABLE)); $result = $connection->query("SHOW FULL COLUMNS FROM " . idf_escape($TABLE));
if (!$result) { if (!$result) {
$error = h($dbh->error); $error = h($connection->error);
} }
$table_status = ($result ? table_status($TABLE) : array()); $table_status = ($result ? table_status($TABLE) : array());
@ -55,9 +55,9 @@ if ($result) {
echo '<p><a href="' . h(ME) . 'foreign=' . urlencode($TABLE) . '">' . lang('Add foreign key') . "</a>\n"; echo '<p><a href="' . h(ME) . 'foreign=' . urlencode($TABLE) . '">' . lang('Add foreign key') . "</a>\n";
} }
if ($dbh->server_info >= 5) { if ($connection->server_info >= 5) {
echo "<h3>" . lang('Triggers') . "</h3>\n"; echo "<h3>" . lang('Triggers') . "</h3>\n";
$result = $dbh->query("SHOW TRIGGERS LIKE " . $dbh->quote(addcslashes($TABLE, "%_"))); $result = $connection->query("SHOW TRIGGERS LIKE " . $connection->quote(addcslashes($TABLE, "%_")));
if ($result->num_rows) { if ($result->num_rows) {
echo "<table cellspacing='0'>\n"; echo "<table cellspacing='0'>\n";
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {

View file

@ -21,7 +21,7 @@ $row = array("Trigger" => $TABLE . "_bi");
if ($_POST) { if ($_POST) {
$row = $_POST; $row = $_POST;
} elseif (strlen($_GET["name"])) { } elseif (strlen($_GET["name"])) {
$result = $dbh->query("SHOW TRIGGERS WHERE `Trigger` = " . $dbh->quote($_GET["name"])); $result = $connection->query("SHOW TRIGGERS WHERE `Trigger` = " . $connection->quote($_GET["name"]));
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
} }
?> ?>

View file

@ -1,7 +1,7 @@
<?php <?php
$USER = $_GET["user"]; $USER = $_GET["user"];
$privileges = array("" => array("All privileges" => "")); $privileges = array("" => array("All privileges" => ""));
$result = $dbh->query("SHOW PRIVILEGES"); $result = $connection->query("SHOW PRIVILEGES");
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
foreach (explode(",", ($row["Privilege"] == "Grant option" ? "" : $row["Context"])) as $context) { foreach (explode(",", ($row["Privilege"] == "Grant option" ? "" : $row["Context"])) as $context) {
$privileges[$context][$row["Privilege"]] = $row["Comment"]; $privileges[$context][$row["Privilege"]] = $row["Comment"];
@ -27,7 +27,7 @@ if ($_POST) {
} }
$grants = array(); $grants = array();
$old_pass = ""; $old_pass = "";
if (isset($_GET["host"]) && ($result = $dbh->query("SHOW GRANTS FOR " . $dbh->quote($USER) . "@" . $dbh->quote($_GET["host"])))) { //! use information_schema for MySQL 5 - column names in column privileges are not escaped if (isset($_GET["host"]) && ($result = $connection->query("SHOW GRANTS FOR " . $connection->quote($USER) . "@" . $connection->quote($_GET["host"])))) { //! use information_schema for MySQL 5 - column names in column privileges are not escaped
while ($row = $result->fetch_row()) { while ($row = $result->fetch_row()) {
if (preg_match('~GRANT (.*) ON (.*) TO ~', $row[0], $match) && preg_match_all('~ *([^(,]*[^ ,(])( *\\([^)]+\\))?~', $match[1], $matches, PREG_SET_ORDER)) { //! escape the part between ON and TO if (preg_match('~GRANT (.*) ON (.*) TO ~', $row[0], $match) && preg_match_all('~ *([^(,]*[^ ,(])( *\\([^)]+\\))?~', $match[1], $matches, PREG_SET_ORDER)) { //! escape the part between ON and TO
foreach ($matches as $val) { foreach ($matches as $val) {
@ -44,16 +44,16 @@ if (isset($_GET["host"]) && ($result = $dbh->query("SHOW GRANTS FOR " . $dbh->qu
} }
if ($_POST && !$error) { if ($_POST && !$error) {
$old_user = (isset($_GET["host"]) ? $dbh->quote($USER) . "@" . $dbh->quote($_GET["host"]) : "''"); $old_user = (isset($_GET["host"]) ? $connection->quote($USER) . "@" . $connection->quote($_GET["host"]) : "''");
$new_user = $dbh->quote($_POST["user"]) . "@" . $dbh->quote($_POST["host"]); // if $_GET["host"] is not set then $new_user is always different $new_user = $connection->quote($_POST["user"]) . "@" . $connection->quote($_POST["host"]); // if $_GET["host"] is not set then $new_user is always different
$pass = $dbh->quote($_POST["pass"]); $pass = $connection->quote($_POST["pass"]);
if ($_POST["drop"]) { if ($_POST["drop"]) {
query_redirect("DROP USER $old_user", ME . "privileges=", lang('User has been dropped.')); query_redirect("DROP USER $old_user", ME . "privileges=", lang('User has been dropped.'));
} else { } else {
if ($old_user == $new_user) { if ($old_user == $new_user) {
queries("SET PASSWORD FOR $new_user = " . ($_POST["hashed"] ? $pass : "PASSWORD($pass)")); queries("SET PASSWORD FOR $new_user = " . ($_POST["hashed"] ? $pass : "PASSWORD($pass)"));
} else { } else {
$error = !queries(($dbh->server_info < 5 ? "GRANT USAGE ON *.* TO" : "CREATE USER") . " $new_user IDENTIFIED BY" . ($_POST["hashed"] ? " PASSWORD" : "") . " $pass"); $error = !queries(($connection->server_info < 5 ? "GRANT USAGE ON *.* TO" : "CREATE USER") . " $new_user IDENTIFIED BY" . ($_POST["hashed"] ? " PASSWORD" : "") . " $pass");
} }
if (!$error) { if (!$error) {
$revoke = array(); $revoke = array();
@ -94,7 +94,7 @@ if ($_POST && !$error) {
query_redirect(queries(), ME . "privileges=", (isset($_GET["host"]) ? lang('User has been altered.') : lang('User has been created.')), !$error, false, $error); query_redirect(queries(), ME . "privileges=", (isset($_GET["host"]) ? lang('User has been altered.') : lang('User has been created.')), !$error, false, $error);
if ($old_user != $new_user) { if ($old_user != $new_user) {
// delete new user in case of an error // delete new user in case of an error
$dbh->query("DROP USER $new_user"); $connection->query("DROP USER $new_user");
} }
} }
} }
@ -105,7 +105,7 @@ if ($_POST) {
$row = $_POST; $row = $_POST;
$grants = $new_grants; $grants = $new_grants;
} else { } else {
$row = $_GET + array("host" => $dbh->result($dbh->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', -1)"))); // create user on the same domain by default $row = $_GET + array("host" => $connection->result($connection->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', -1)"))); // create user on the same domain by default
$row["pass"] = $old_pass; $row["pass"] = $old_pass;
if (strlen($old_pass)) { if (strlen($old_pass)) {
$row["hashed"] = true; $row["hashed"] = true;

View file

@ -2,7 +2,7 @@
page_header(lang('Variables')); page_header(lang('Variables'));
echo "<table cellspacing='0'>\n"; echo "<table cellspacing='0'>\n";
$result = $dbh->query("SHOW VARIABLES"); $result = $connection->query("SHOW VARIABLES");
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
echo "<tr>"; echo "<tr>";
echo "<th><code class='jush-sqlset'>" . h($row["Variable_name"]) . "</code>"; echo "<th><code class='jush-sqlset'>" . h($row["Variable_name"]) . "</code>";

View file

@ -1,3 +1,10 @@
Adminer 2.1.1-dev:
Display table links above table structure
Fix removed default in ALTER
Display whitespace in texts (bug #2858042)
Move <h1> to $adminer->navigation (customization)
Rename get_dbh to connection (customization)
Adminer 2.1.0 (released 2009-09-12): Adminer 2.1.0 (released 2009-09-12):
Edit default values directly in table creation Edit default values directly in table creation
Execute SQL file stored on server disk Execute SQL file stored on server disk

View file

@ -10,10 +10,10 @@ class Adminer {
} }
function database() { function database() {
global $dbh; global $connection;
$dbs = get_databases(false); $dbs = get_databases(false);
return (!$dbs return (!$dbs
? $dbh->result($dbh->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1)")) // username without the database list ? $connection->result($connection->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1)")) // username without the database list
: $dbs[(information_schema($dbs[0]) ? 1 : 0)] // first available database : $dbs[(information_schema($dbs[0]) ? 1 : 0)] // first available database
); );
} }
@ -47,13 +47,13 @@ class Adminer {
} }
function backwardKeys($table) { function backwardKeys($table) {
global $dbh; global $connection;
$return = array(); $return = array();
$result = $dbh->query("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME $result = $connection->query("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
FROM information_schema.KEY_COLUMN_USAGE FROM information_schema.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = " . $dbh->quote($this->database()) . " WHERE TABLE_SCHEMA = " . $connection->quote($this->database()) . "
AND REFERENCED_TABLE_SCHEMA = " . $dbh->quote($this->database()) . " AND REFERENCED_TABLE_SCHEMA = " . $connection->quote($this->database()) . "
AND REFERENCED_TABLE_NAME = " . $dbh->quote($table) . " AND REFERENCED_TABLE_NAME = " . $connection->quote($table) . "
ORDER BY ORDINAL_POSITION"); //! requires MySQL 5 ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
if ($result) { if ($result) {
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
@ -78,7 +78,7 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
} }
function rowDescriptions($rows, $foreignKeys) { function rowDescriptions($rows, $foreignKeys) {
global $dbh; global $connection;
$return = $rows; $return = $rows;
foreach ($rows[0] as $key => $val) { foreach ($rows[0] as $key => $val) {
foreach ((array) $foreignKeys[$key] as $foreignKey) { foreach ((array) $foreignKeys[$key] as $foreignKey) {
@ -89,11 +89,11 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
// find all used ids // find all used ids
$ids = array(); $ids = array();
foreach ($rows as $row) { foreach ($rows as $row) {
$ids[$row[$key]] = $dbh->quote($row[$key]); $ids[$row[$key]] = $connection->quote($row[$key]);
} }
// uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow // uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow
$descriptions = array(); $descriptions = array();
$result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreignKey["table"]) . " WHERE $id IN (" . implode(", ", $ids) . ")"); $result = $connection->query("SELECT $id, $name FROM " . idf_escape($foreignKey["table"]) . " WHERE $id IN (" . implode(", ", $ids) . ")");
while ($row = $result->fetch_row()) { while ($row = $result->fetch_row()) {
$descriptions[$row[0]] = $row[1]; $descriptions[$row[0]] = $row[1];
} }
@ -254,7 +254,7 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
} }
function selectEmailProcess($where, $foreignKeys) { function selectEmailProcess($where, $foreignKeys) {
global $dbh; global $connection;
if ($_POST["email_append"]) { if ($_POST["email_append"]) {
return true; return true;
} }
@ -265,7 +265,7 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
$subject = $_POST["email_subject"]; $subject = $_POST["email_subject"];
$message = $_POST["email_message"]; $message = $_POST["email_message"];
preg_match_all('~\\{\\$([a-z0-9_]+)\\}~i', "$subject.$message", $matches); // allows {$name} in subject or message preg_match_all('~\\{\\$([a-z0-9_]+)\\}~i', "$subject.$message", $matches); // allows {$name} in subject or message
$result = $dbh->query("SELECT DISTINCT $field, " . implode(", ", array_map('idf_escape', array_unique($matches[1]))) . " FROM " . idf_escape($_GET["select"]) $result = $connection->query("SELECT DISTINCT $field, " . implode(", ", array_map('idf_escape', array_unique($matches[1]))) . " FROM " . idf_escape($_GET["select"])
. " WHERE $field IS NOT NULL AND $field != ''" . " WHERE $field IS NOT NULL AND $field != ''"
. ($where ? " AND " . implode(" AND ", $where) : "") . ($where ? " AND " . implode(" AND ", $where) : "")
. ($_POST["all"] ? "" : " AND ((" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . "))") . ($_POST["all"] ? "" : " AND ((" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . "))")
@ -310,15 +310,15 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
} }
function editInput($table, $field, $attrs, $value) { function editInput($table, $field, $attrs, $value) {
global $dbh; global $connection;
$foreign_keys = column_foreign_keys($table); $foreign_keys = column_foreign_keys($table);
foreach ((array) $foreign_keys[$field["field"]] as $foreign_key) { foreach ((array) $foreign_keys[$field["field"]] as $foreign_key) {
if (count($foreign_key["source"]) == 1) { if (count($foreign_key["source"]) == 1) {
$id = idf_escape($foreign_key["target"][0]); $id = idf_escape($foreign_key["target"][0]);
$name = $this->rowDescription($foreign_key["table"]); $name = $this->rowDescription($foreign_key["table"]);
if (strlen($name) && $dbh->result($dbh->query("SELECT COUNT(*) FROM " . idf_escape($foreign_key["table"]))) <= 1000) { // optionlist with more than 1000 options would be too big if (strlen($name) && $connection->result($connection->query("SELECT COUNT(*) FROM " . idf_escape($foreign_key["table"]))) <= 1000) { // optionlist with more than 1000 options would be too big
$return = array("" => ""); $return = array("" => "");
$result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreign_key["table"]) . " ORDER BY 2"); $result = $connection->query("SELECT $id, $name FROM " . idf_escape($foreign_key["table"]) . " ORDER BY 2");
while ($row = $result->fetch_row()) { while ($row = $result->fetch_row()) {
$return[$row[0]] = $row[1]; $return[$row[0]] = $row[1];
} }
@ -336,11 +336,11 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
} }
function processInput($field, $value, $function = "") { function processInput($field, $value, $function = "") {
global $dbh; global $connection;
if ($function == "now") { if ($function == "now") {
return "$function()"; return "$function()";
} }
$return = $dbh->quote(ereg('date|timestamp', $field["type"]) && preg_match('(^' . str_replace('\\$1', '(?P<p1>[0-9]+)', preg_replace('~(\\\\\\$([2-6]))~', '(?P<p\\2>[0-9]{1,2})', preg_quote(lang('$1-$3-$5')))) . '(.*))', $value, $match) $return = $connection->quote(ereg('date|timestamp', $field["type"]) && preg_match('(^' . str_replace('\\$1', '(?P<p1>[0-9]+)', preg_replace('~(\\\\\\$([2-6]))~', '(?P<p\\2>[0-9]{1,2})', preg_quote(lang('$1-$3-$5')))) . '(.*))', $value, $match)
? ($match["p1"] ? $match["p1"] : ($match["p2"] < 70 ? 20 : 19) . $match["p2"]) . "-$match[p3]$match[p4]-$match[p5]$match[p6]" . end($match) ? ($match["p1"] ? $match["p1"] : ($match["p2"] < 70 ? 20 : 19) . $match["p2"]) . "-$match[p3]$match[p4]-$match[p5]$match[p6]" . end($match)
: $value : $value
); );

View file

@ -1,2 +1,2 @@
<?php <?php
$dbh->select_db($adminer->database()); $connection->select_db($adminer->database());

View file

@ -4,8 +4,8 @@ function dump_table($table) {
} }
function dump_data($table, $style, $select = "") { function dump_data($table, $style, $select = "") {
global $dbh; global $connection;
$result = $dbh->query(($select ? $select : "SELECT * FROM " . idf_escape($table))); $result = $connection->query(($select ? $select : "SELECT * FROM " . idf_escape($table)));
if ($result) { if ($result) {
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
dump_csv($row); dump_csv($row);

View file

@ -11,7 +11,7 @@ IE6 - <label for>
Offer enum and set items in search - whisperer Offer enum and set items in search - whisperer
Use event $intervals + microseconds in relative date functions Use event $intervals + microseconds in relative date functions
? Column and table names auto-completition in SQL textarea ? Column and table names auto-completition in SQL textarea
? Aliasing of built-in functions can save 7 KB, function minification can save 7 KB, substitution of repetitive $a["a"] can save 4 KB, substitution of $_GET and friends can save 2 KB, JS packer can save 1 KB, not enclosing HTML attribute values can save 1.2 KB ? Aliasing of built-in functions can save 7 KB, function minification can save 7 KB, substitution of repetitive $a["a"] can save 4 KB, substitution of $_GET and friends can save 2 KB, JS packer can save 1 KB, not enclosing HTML attribute values can save 1.2 KB, replacing \\n by \n can save .3 KB
? Branch binary_compile: LZW compression of translations can save 30 KB, LZW compression of all texts can save 11 KB, remove of base64_decode() + using chars 127-255 in minification can save 1 KB ? Branch binary_compile: LZW compression of translations can save 30 KB, LZW compression of all texts can save 11 KB, remove of base64_decode() + using chars 127-255 in minification can save 1 KB
? AJAX editing - select page has all data to display edit form ? AJAX editing - select page has all data to display edit form