$row["fields"][] = $field;
}
if ($dbh->server_info >= 5.1) {
- $from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . $dbh->quote($_GET["db"]) . " AND TABLE_NAME = " . $dbh->quote($_GET["create"]);
+ $from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . $dbh->quote(DB) . " AND TABLE_NAME = " . $dbh->quote($_GET["create"]);
$result = $dbh->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();
$row["partition_names"] = array();
if ($_POST && !$error && !isset($_POST["add_x"])) { // add is an image and PHP changes add.x to add_x
if ($_POST["drop"]) {
unset($_SESSION["databases"][$_GET["server"]]);
- query_redirect("DROP DATABASE " . idf_escape($_GET["db"]), substr(preg_replace('~db=[^&]*&~', '', ME), 0, -1), lang('Database has been dropped.'));
- } elseif ($_GET["db"] !== $_POST["name"]) {
+ query_redirect("DROP DATABASE " . idf_escape(DB), substr(preg_replace('~db=[^&]*&~', '', ME), 0, -1), lang('Database has been dropped.'));
+ } elseif (DB !== $_POST["name"]) {
// create or rename database
unset($_SESSION["databases"][$_GET["server"]]); // clear cache
$dbs = explode("\n", str_replace("\r", "", $_POST["name"]));
$last = $db;
}
}
- if (query_redirect(queries(), ME . "db=" . urlencode($last), lang('Database has been created.'), !strlen($_GET["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");
while ($row = $result->fetch_row()) {
if (!queries("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) {
}
}
if (!$row) {
- queries("DROP DATABASE " . idf_escape($_GET["db"]));
+ queries("DROP DATABASE " . idf_escape(DB));
}
query_redirect(queries(), preg_replace('~db=[^&]*&~', '', ME) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'), !$row, false, $row);
}
}
}
-page_header(strlen($_GET["db"]) ? lang('Alter database') : lang('Create database'), $error, array(), $_GET["db"]);
+page_header(strlen(DB) ? lang('Alter database') : lang('Create database'), $error, array(), DB);
$collations = collations();
-$name = $_GET["db"];
+$name = DB;
$collate = array();
if ($_POST) {
$name = $_POST["name"];
$collate = $_POST["collation"];
-} elseif (!strlen($_GET["db"])) {
+} elseif (!strlen(DB)) {
// propose database name with limited privileges
$result = $dbh->query("SHOW GRANTS");
while ($row = $result->fetch_row()) {
break;
}
}
-} elseif (($result = $dbh->query("SHOW CREATE DATABASE " . idf_escape($_GET["db"])))) {
+} elseif (($result = $dbh->query("SHOW CREATE DATABASE " . idf_escape(DB)))) {
$create = $dbh->result($result, 1);
if (preg_match('~ COLLATE ([^ ]+)~', $create, $match)) {
$collate = $match[1];
<input type="hidden" name="token" value="<?php echo $token; ?>">
<input type="submit" value="<?php echo lang('Save'); ?>">
<?php
-if (strlen($_GET["db"])) {
+if (strlen(DB)) {
echo "<input type='submit' name='drop' value='" . lang('Drop') . "'$confirm>\n";
} elseif (!$_POST["add_x"]) {
echo "<input type='image' name='add' src='../adminer/plus.gif' alt='+' title='" . lang('Add next') . "'>\n";
query_redirect(queries(), substr(ME, 0, -1), $message, $result, false, !$result);
}
-page_header(lang('Database') . ": " . h($_GET["db"]), $error, false);
+page_header(lang('Database') . ": " . h(DB), $error, false);
echo '<p><a href="' . h(ME) . 'database=">' . lang('Alter database') . "</a>\n";
echo '<p><a href="' . h(ME) . 'schema=">' . lang('Database schema') . "</a>\n";
echo "<p><input type='hidden' name='token' value='$token'><input type='submit' value='" . lang('Analyze') . "'> <input type='submit' name='optimize' value='" . lang('Optimize') . "'> <input type='submit' name='check' value='" . lang('Check') . "'> <input type='submit' name='repair' value='" . lang('Repair') . "'> <input type='submit' name='truncate' value='" . lang('Truncate') . "'$confirm> <input type='submit' name='drop' value='" . lang('Drop') . "'$confirm>\n";
$dbs = get_databases();
if (count($dbs) != 1) {
- $db = (isset($_POST["target"]) ? $_POST["target"] : $_GET["db"]);
+ $db = (isset($_POST["target"]) ? $_POST["target"] : DB);
echo "<p>" . lang('Move to other database') . ($dbs ? ": <select name='target'>" . optionlist($dbs, $db) . "</select>" : ': <input name="target" value="' . h($db) . '">') . " <input type='submit' name='move' value='" . lang('Move') . "'>\n";
}
echo "</form>\n";
if ($dbh->server_info >= 5) {
echo '<p><a href="' . h(ME) . 'view=">' . lang('Create view') . "</a>\n";
echo "<h3>" . lang('Routines') . "</h3>\n";
- $result = $dbh->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $dbh->quote($_GET["db"]));
+ $result = $dbh->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $dbh->quote(DB));
if ($result->num_rows) {
echo "<table cellspacing='0'>\n";
while ($row = $result->fetch_assoc()) {
}
if ($_POST) {
- $ext = dump_headers((strlen($_GET["dump"]) ? $_GET["dump"] : $_GET["db"]), (!strlen($_GET["db"]) || count((array) $_POST["tables"] + (array) $_POST["data"]) > 1));
+ $ext = dump_headers((strlen($_GET["dump"]) ? $_GET["dump"] : DB), (!strlen(DB) || count((array) $_POST["tables"] + (array) $_POST["data"]) > 1));
if ($_POST["format"] == "sql") {
dump("SET NAMES utf8;
SET foreign_key_checks = 0;
}
$style = $_POST["db_style"];
- foreach ((strlen($_GET["db"]) ? array($_GET["db"]) : (array) $_POST["databases"]) as $db) {
+ foreach ((strlen(DB) ? array(DB) : (array) $_POST["databases"]) as $db) {
if ($dbh->select_db($db)) {
if ($_POST["format"] == "sql" && ereg('CREATE', $style) && ($result = $dbh->query("SHOW CREATE DATABASE " . idf_escape($db)))) {
if ($style == "DROP+CREATE") {
if ($_POST["table_style"] || $_POST["data_style"]) {
$views = array();
foreach (table_status() as $row) {
- $table = (!strlen($_GET["db"]) || in_array($row["Name"], (array) $_POST["tables"]));
- $data = (!strlen($_GET["db"]) || in_array($row["Name"], (array) $_POST["data"]));
+ $table = (!strlen(DB) || in_array($row["Name"], (array) $_POST["tables"]));
+ $data = (!strlen(DB) || in_array($row["Name"], (array) $_POST["data"]));
if ($table || $data) {
if (isset($row["Engine"])) {
if ($ext == "tar") {
dump_triggers($row["Name"], $_POST["table_style"]);
}
if ($ext == "tar") {
- dump(tar_file((strlen($_GET["db"]) ? "" : "$db/") . "$row[Name].csv", ob_get_clean()));
+ dump(tar_file((strlen(DB) ? "" : "$db/") . "$row[Name].csv", ob_get_clean()));
} elseif ($_POST["format"] == "sql") {
dump("\n");
}
exit;
}
-page_header(lang('Export'), "", (strlen($_GET["export"]) ? array("table" => $_GET["export"]) : array()), $_GET["db"]);
+page_header(lang('Export'), "", (strlen($_GET["export"]) ? array("table" => $_GET["export"]) : array()), DB);
?>
<form action="" method="post">
echo "<tr><th>" . lang('Output') . "<td><input type='hidden' name='token' value='$token'>$dump_output\n"; // token is not needed but checked in bootstrap for all POST data
echo "<tr><th>" . lang('Format') . "<td>$dump_format\n";
echo "<tr><th>" . lang('Compression') . "<td>" . ($dump_compress ? $dump_compress : lang('None of the supported PHP extensions (%s) are available.', 'zlib, bz2')) . "\n";
-echo "<tr><th>" . lang('Database') . "<td><select name='db_style'>" . optionlist($db_style, (strlen($_GET["db"]) ? '' : 'CREATE')) . "</select>\n";
+echo "<tr><th>" . lang('Database') . "<td><select name='db_style'>" . optionlist($db_style, (strlen(DB) ? '' : 'CREATE')) . "</select>\n";
echo "<tr><th>" . lang('Tables') . "<td><select name='table_style'>" . optionlist($table_style, 'DROP+CREATE') . "</select>\n";
echo "<tr><th>" . lang('Data') . "<td><select name='data_style'>" . optionlist($data_style, 'INSERT') . "</select>\n";
?>
<table cellspacing="0">
<?php
-if (strlen($_GET["db"])) {
+if (strlen(DB)) {
$checked = (strlen($_GET["dump"]) ? "" : " checked");
echo "<thead><tr>";
echo "<th style='text-align: left;'><label><input type='checkbox' id='check-tables'$checked onclick='form_check(this, /^tables\\[/);'>" . lang('Tables') . "</label>";
if ($_POST) {
$row = $_POST;
} elseif (strlen($_GET["event"])) {
- $result = $dbh->query("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = " . $dbh->quote($_GET["db"]) . " AND EVENT_NAME = " . $dbh->quote($_GET["event"]));
+ $result = $dbh->query("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = " . $dbh->quote(DB) . " AND EVENT_NAME = " . $dbh->quote($_GET["event"]));
$row = $result->fetch_assoc();
}
?>
* @return string
*/
function database() {
- // should be used everywhere instead of $_GET["db"]
- return $_GET["db"];
+ // should be used everywhere instead of DB
+ return DB;
}
/** Print login form
*/
function messageQuery($query) {
$id = "sql-" . count($_SESSION["messages"]);
- $_SESSION["history"][$_GET["server"]][$_GET["db"]][] = $query;
- return " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-sql'>" . h($query) . '</pre><a href="' . h(ME . 'sql=&history=' . (count($_SESSION["history"][$_GET["server"]][$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a></div>';
+ $_SESSION["history"][$_GET["server"]][DB][] = $query;
+ return " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-sql'>" . h($query) . '</pre><a href="' . h(ME . 'sql=&history=' . (count($_SESSION["history"][$_GET["server"]][DB]) - 1)) . '">' . lang('Edit') . '</a></div>';
}
/** Functions displayed in edit form
<form action="">
<p><?php if (strlen($_GET["server"])) { ?><input type="hidden" name="server" value="<?php echo h($_GET["server"]); ?>"><?php } ?>
<?php if ($databases) { ?>
-<select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)<?php echo optionlist($databases, $_GET["db"]); ?></select>
+<select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)<?php echo optionlist($databases, DB); ?></select>
<?php } else { ?>
-<input name="db" value="<?php echo h($_GET["db"]); ?>">
+<input name="db" value="<?php echo h(DB); ?>">
<?php } ?>
<?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value=""><?php } ?>
<?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value=""><?php } ?>
</p>
</form>
<?php
- if ($missing != "db" && strlen($_GET["db"])) {
+ if ($missing != "db" && strlen(DB)) {
$result = $dbh->query("SHOW TABLES");
if (!$result) {
echo "<p class='error'>" . lang('No tables.') . "\n";
set_magic_quotes_runtime(false);
@set_time_limit(0); // @ - can be disabled
-define("ME", preg_replace('~^[^?]*/([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"]) . '?' . (strlen($_GET["server"]) ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (strlen($_GET["db"]) ? 'db=' . urlencode($_GET["db"]) . '&' : ''));
+define("DB", $_GET["db"]); // for the sake of speed and size
+define("ME", preg_replace('~^[^?]*/([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"]) . '?' . (strlen($_GET["server"]) ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (strlen(DB) ? 'db=' . urlencode(DB) . '&' : ''));
$on_actions = array("RESTRICT", "CASCADE", "SET NULL", "NO ACTION"); // used in foreign_keys()
include "../adminer/include/version.inc.php";
<?php
function connect_error() {
global $dbh, $VERSION;
- if (strlen($_GET["db"])) {
- page_header(lang('Database') . ": " . h($_GET["db"]), lang('Invalid database.'), false);
+ if (strlen(DB)) {
+ page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), false);
} else {
page_header(lang('Select database'), "", null);
foreach (array(
page_footer("db");
}
-if (!(strlen($_GET["db"]) ? $dbh->select_db($_GET["db"]) : isset($_GET["sql"]) || isset($_GET["dump"]) || isset($_GET["database"]) || isset($_GET["processlist"]) || isset($_GET["privileges"]) || isset($_GET["user"]) || isset($_GET["variables"]))) {
- if (strlen($_GET["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)) {
unset($_SESSION["databases"][$_GET["server"]]);
}
connect_error(); // separate function to catch SQLite error
$link = substr(preg_replace('~db=[^&]*&~', '', ME), 0, -1);
echo '<p id="breadcrumb"><a href="' . (strlen($link) ? h($link) : ".") . '">' . (isset($_GET["server"]) ? h($_GET["server"]) : lang('Server')) . '</a> » ';
if (is_array($breadcrumb)) {
- if (strlen($_GET["db"])) {
- echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["db"]) . '</a> » ';
+ if (strlen(DB)) {
+ echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h(DB) . '</a> » ';
}
foreach ($breadcrumb as $key => $val) {
$desc = (is_array($val) ? $val[1] : $val);
$_SESSION["messages"] = array();
}
$databases = &$_SESSION["databases"][$_GET["server"]];
- if (strlen($_GET["db"]) && $databases && !in_array($_GET["db"], $databases, true)) {
+ if (strlen(DB) && $databases && !in_array(DB, $databases, true)) {
$databases = null;
}
if (isset($databases) && !isset($_GET["sql"])) {
<?php
-page_header(lang('Database schema'), "", array(), $_GET["db"]);
+page_header(lang('Database schema'), "", array(), DB);
$table_pos = array();
$table_pos_js = array();
echo "<form action='' id='form'>\n";
echo "<div style='display: none;'>";
echo (strlen($_GET["server"]) ? '<input type="hidden" name="server" value="' . h($_GET["server"]) . '">' : "");
- echo (strlen($_GET["db"]) ? '<input type="hidden" name="db" value="' . h($_GET["db"]) . '">' : ""); // not used in Editor
+ echo (strlen(DB) ? '<input type="hidden" name="db" value="' . h(DB) . '">' : ""); // not used in Editor
echo '<input type="hidden" name="select" value="' . h($_GET["select"]) . '">';
echo "</div>\n";
$adminer->selectColumnsPrint($select, $columns);
echo ($table_names ? "<th>" . lang('Relations') : "") . "</thead>\n";
foreach ($descriptions as $n => $row) {
$unique_idf = implode('&', unique_idf($rows[$n], $indexes));
- echo "<tr" . odd() . "><td><input type='checkbox' name='check[]' value='$unique_idf' onclick=\"this.form['all'].checked = false; form_uncheck('all-page');\">" . (count($select) != count($group) || information_schema($_GET["db"]) ? '' : " <a href='" . h(ME) . "edit=" . urlencode($_GET['select']) . "&$unique_idf'>" . lang('edit') . "</a>");
+ echo "<tr" . odd() . "><td><input type='checkbox' name='check[]' value='$unique_idf' onclick=\"this.form['all'].checked = false; form_uncheck('all-page');\">" . (count($select) != count($group) || information_schema(DB) ? '' : " <a href='" . h(ME) . "edit=" . urlencode($_GET['select']) . "&$unique_idf'>" . lang('edit') . "</a>");
foreach ($row as $key => $val) {
if (isset($names[$key])) {
if (strlen($val) && (!isset($email_fields[$key]) || strlen($email_fields[$key]))) {
}
echo " (" . lang('%d row(s)', $found_rows) . ') <label><input type="checkbox" name="all" value="1">' . lang('whole result') . "</label>\n";
- echo (information_schema($_GET["db"]) ? "" : "<fieldset><legend>" . lang('Edit') . "</legend><div><input type='submit' name='edit' value='" . lang('Edit') . "'> <input type='submit' name='clone' value='" . lang('Clone') . "'> <input type='submit' name='delete' value='" . lang('Delete') . "'$confirm></div></fieldset>\n");
+ echo (information_schema(DB) ? "" : "<fieldset><legend>" . lang('Edit') . "</legend><div><input type='submit' name='edit' value='" . lang('Edit') . "'> <input type='submit' name='clone' value='" . lang('Clone') . "'> <input type='submit' name='delete' value='" . lang('Delete') . "'$confirm></div></fieldset>\n");
echo "<fieldset><legend>" . lang('Export') . "</legend><div>$dump_output $dump_format $dump_compress <input type='submit' name='export' value='" . lang('Export') . "'></div></fieldset>\n";
}
echo "<fieldset><legend>" . lang('CSV Import') . "</legend><div><input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> <input type='submit' name='import' value='" . lang('Import') . "'></div></fieldset>\n";
<?php
-$history = &$_SESSION["history"][$_GET["server"]][$_GET["db"]];
+$history = &$_SESSION["history"][$_GET["server"]][DB];
if (!$error && $_POST["clear"]) {
$history = array();
redirect(remove_from_uri("history"));
$delimiter = ";";
$offset = 0;
$empty = true;
- $dbh2 = (strlen($_GET["db"]) ? connect() : null); // connection for exploring indexes (to not replace FOUND_ROWS()) //! PDO - silent error
+ $dbh2 = (strlen(DB) ? connect() : null); // connection for exploring indexes (to not replace FOUND_ROWS()) //! PDO - silent error
if (is_object($dbh2)) {
- $dbh2->select_db($_GET["db"]);
+ $dbh2->select_db(DB);
}
while (strlen($query)) {
if (!$offset && preg_match('~^\\s*DELIMITER\\s+(.+)~i', $query, $match)) {
?>
<form action="" method="post" enctype="multipart/form-data">
-<p><textarea name="query" rows="20" cols="80" style="width: 98%;"><?php echo h($_POST ? $_POST["query"] : (strlen($_GET["history"]) ? $_SESSION["history"][$_GET["server"]][$_GET["db"]][$_GET["history"]] : $_GET["sql"])); ?></textarea>
+<p><textarea name="query" rows="20" cols="80" style="width: 98%;"><?php echo h($_POST ? $_POST["query"] : (strlen($_GET["history"]) ? $_SESSION["history"][$_GET["server"]][DB][$_GET["history"]] : $_GET["sql"])); ?></textarea>
<p>
<input type="hidden" name="token" value="<?php echo $token; ?>">
<input type="submit" value="<?php echo lang('Execute'); ?>">
<?php
-$_GET["db"] = ""; // used here and there by Adminer
$dbh->select_db($adminer->database());