$call[] = (isset($out[$key]) ? "@" . idf_escape($field["field"]) : $val);
}
$query = (isset($_GET["callf"]) ? "SELECT" : "CALL") . " " . idf_escape($PROCEDURE) . "(" . implode(", ", $call) . ")";
- echo "<p><code class='jush-$driver'>" . h($query) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
+ echo "<p><code class='jush-$jush'>" . h($query) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
if (!$connection->multi_query($query)) {
echo "<p class='error'>" . error() . "\n";
} else {
$collate = $_POST["collation"];
} elseif (DB != "") {
$collate = db_collation(DB, $collations);
-} elseif ($driver == "sql") {
+} elseif ($jush == "sql") {
// propose database name with limited privileges
foreach (get_vals("SHOW GRANTS") as $grant) {
if (preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~', $grant, $match) && $match[1]) {
if ($tables_views && !$error && !$_POST["search"]) {
$result = true;
$message = "";
- if ($driver == "sql" && count($_POST["tables"]) > 1 && ($_POST["drop"] || $_POST["truncate"])) {
+ if ($jush == "sql" && count($_POST["tables"]) > 1 && ($_POST["drop"] || $_POST["truncate"])) {
queries("SET foreign_key_checks = 0"); // allows to truncate or drop several tables at once
}
if ($_POST["truncate"]) {
}
echo "</table>\n";
if (!information_schema(DB)) {
- echo "<p><input type='hidden' name='token' value='$token'>" . ($driver == "sql" ? "<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') . "' onclick=\"return confirm('" . lang('Are you sure?') . " (' + formChecked(this, /tables/) + ')');\"> <input type='submit' name='drop' value='" . lang('Drop') . "' onclick=\"return confirm('" . lang('Are you sure?') . " (' + formChecked(this, /tables|views/) + ')');\">\n";
+ echo "<p><input type='hidden' name='token' value='$token'>" . ($jush == "sql" ? "<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') . "' onclick=\"return confirm('" . lang('Are you sure?') . " (' + formChecked(this, /tables/) + ')');\"> <input type='submit' name='drop' value='" . lang('Drop') . "' onclick=\"return confirm('" . lang('Are you sure?') . " (' + formChecked(this, /tables|views/) + ')');\">\n";
$dbs = (support("scheme") ? schemas() : get_databases());
- if (count($dbs) != 1 && $driver != "sqlite") {
+ if (count($dbs) != 1 && $jush != "sqlite") {
$db = (isset($_POST["target"]) ? $_POST["target"] : (support("scheme") ? $_GET["ns"] : DB));
echo "<p>" . lang('Move to other database') . ($dbs ? ": " . html_select("target", $dbs, $db) : ': <input name="target" value="' . h($db) . '">') . " <input type='submit' name='move' value='" . lang('Move') . "'>\n";
}
return ereg('^(trigger|drop_col)$', $feature); //! view|routine|scheme|
}
- $driver = "mssql";
+ $jush = "mssql";
$types = array();
$structured_types = array();
foreach (array(
return !ereg("scheme|sequence" . ($connection->server_info < 5.1 ? "|event|partitioning" . ($connection->server_info < 5 ? "|view|routine|trigger" : "") : ""), $feature);
}
- $driver = "sql"; ///< @var string JUSH identifier
+ $jush = "sql"; ///< @var string JUSH identifier
$types = array(); ///< @var array ($type => $maximum_unsigned_length, ...)
$structured_types = array(); ///< @var array ($description => array($type, ...), ...)
foreach (array(
return ereg('^(comment|view|scheme|sequence|trigger|variables|drop_col)$', $feature); //! routine|
}
- $driver = "pgsql";
+ $jush = "pgsql";
$types = array();
$structured_types = array();
foreach (array( //! arrays
return ereg('^(view|trigger|variables|status)$', $feature);
}
- $driver = "sqlite";
+ $jush = "sqlite";
$types = array("integer" => 0, "real" => 0, "numeric" => 0, "text" => 0, "blob" => 0);
$structured_types = array_keys($types);
$unsigned = array();
if ($_POST["format"] == "sql") {
echo "-- Adminer $VERSION " . $drivers[DRIVER] . " dump
-" . ($driver != "sql" ? "" : "SET NAMES utf8;
+" . ($jush != "sql" ? "" : "SET NAMES utf8;
SET foreign_key_checks = 0;
SET time_zone = " . $connection->quote($connection->result("SELECT @@time_zone")) . ";
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
$db_style = array('', 'USE', 'DROP+CREATE', 'CREATE');
$table_style = array('', 'DROP+CREATE', 'CREATE');
$data_style = array('', 'TRUNCATE+INSERT', 'INSERT', 'INSERT+UPDATE');
-if ($driver == "sql") {
+if ($jush == "sql") {
$db_style[] = 'CREATE+ALTER';
$table_style[] = 'CREATE+ALTER';
}
$TABLE = $_GET["foreign"];
if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-js"]) {
if ($_POST["drop"]) {
- query_redirect("ALTER TABLE " . idf_escape($TABLE) . "\nDROP " . ($driver == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($_GET["name"]), ME . "table=" . urlencode($TABLE), lang('Foreign key has been dropped.'));
+ query_redirect("ALTER TABLE " . idf_escape($TABLE) . "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($_GET["name"]), ME . "table=" . urlencode($TABLE), lang('Foreign key has been dropped.'));
} else {
$source = array_filter($_POST["source"], 'strlen');
ksort($source); // enforce input order
* @return string
*/
function selectQuery($query) {
- global $driver;
- return "<p><code class='jush-$driver'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
+ global $jush;
+ return "<p><code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
}
/** Description of a row in a table
* @return string
*/
function messageQuery($query) {
- global $driver;
+ global $jush;
restart_session();
$id = "sql-" . count($_SESSION["messages"]);
$history = &get_session("history");
$history[DB][] = (strlen($query) > 1e6 ? ereg_replace('[\x80-\xFF]+$', '', substr($query, 0, 1e6)) . "\n..." : $query); // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
- return " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-$driver'>" . shorten_utf8($query, 1000) . '</pre><p><a href="' . h(ME . 'sql=&history=' . (count($history[DB]) - 1)) . '">' . lang('Edit') . '</a></div>';
+ return " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-$jush'>" . shorten_utf8($query, 1000) . '</pre><p><a href="' . h(ME . 'sql=&history=' . (count($history[DB]) - 1)) . '">' . lang('Edit') . '</a></div>';
}
/** Functions displayed in edit form
* @return null
*/
function navigation($missing) {
- global $VERSION, $connection, $token, $driver, $drivers;
+ global $VERSION, $connection, $token, $jush, $drivers;
?>
<h1>
<a href="http://www.adminer.org/" id="h1"><?php echo $this->name(); ?></a>
<?php
if ($missing == "auth") {
$first = true;
- foreach ((array) $_SESSION["passwords"] as $key => $servers) { // $driver is global variable
+ foreach ((array) $_SESSION["passwords"] as $driver => $servers) {
foreach ($servers as $server => $usernames) {
foreach ($usernames as $username => $password) {
if (isset($password)) {
echo "<p>\n";
$first = false;
}
- echo "<a href='" . h(auth_url($key, $server, $username)) . "'>($drivers[$key]) " . h($username . ($server != "" ? "@$server" : "")) . "</a><br>\n";
+ echo "<a href='" . h(auth_url($driver, $server, $username)) . "'>($drivers[$driver]) " . h($username . ($server != "" ? "@$server" : "")) . "</a><br>\n";
}
}
}
$links[] = preg_quote($table, '/');
}
echo "<script type='text/javascript'>\n";
- echo "var jushLinks = { $driver: [ '" . addcslashes(h(ME), "\\'/") . "table=\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
+ echo "var jushLinks = { $jush: [ '" . addcslashes(h(ME), "\\'/") . "table=\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) {
- echo "jushLinks.$val = jushLinks.$driver;\n";
+ echo "jushLinks.$val = jushLinks.$jush;\n";
}
echo "</script>\n";
}
redirect(substr(preg_replace('~(username|db|ns)=[^&]*&~', '', ME), 0, -1), lang('Logout successful.'));
}
} elseif ($_COOKIE["adminer_permanent"]) {
- list($server, $username, $cipher, $system) = array_map('base64_decode', explode(":", $_COOKIE["adminer_permanent"])); // $driver is a global variable
- if ($server == SERVER && $username === $_GET["username"] && $system == DRIVER) {
+ list($server, $username, $cipher, $driver) = array_map('base64_decode', explode(":", $_COOKIE["adminer_permanent"]));
+ if ($server == SERVER && $username === $_GET["username"] && $driver == DRIVER) {
session_regenerate_id(); // defense against session fixation
set_session("passwords", decrypt_string($cipher, $adminer->permanentLogin()));
}
}
function dump_data($table, $style, $select = "") {
- global $connection, $driver;
- $max_packet = ($driver == "sqlite" ? 0 : 1048576); // default, minimum is 1024
+ global $connection, $jush;
+ $max_packet = ($jush == "sqlite" ? 0 : 1048576); // default, minimum is 1024
if ($style) {
if ($_POST["format"] == "sql" && $style == "TRUNCATE+INSERT") {
echo "TRUNCATE " . idf_escape($table) . ";\n";
* @return null
*/
function input($field, $value, $function) {
- global $types, $adminer, $driver;
+ global $types, $adminer, $jush;
$name = h(bracket_escape($field["field"]));
echo "<td class='function'>";
$functions = (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field);
} elseif (ereg('binary|blob|bytea', $field["type"]) && ini_bool("file_uploads")) {
echo "<input type='file' name='fields-$name'$onchange>";
} elseif (ereg('text|blob', $field["type"])) {
- echo "<textarea " . ($driver != "sqlite" || ereg("\n", $value) ? "cols='50' rows='12'" : "cols='30' rows='1' style='height: 1.2em;'") . "$attrs>" . h($value) . '</textarea>'; // 1.2em - line-height
+ echo "<textarea " . ($jush != "sqlite" || ereg("\n", $value) ? "cols='50' rows='12'" : "cols='30' rows='1' style='height: 1.2em;'") . "$attrs>" . h($value) . '</textarea>'; // 1.2em - line-height
} else {
// int(3) is only a display hint
$maxlength = (!ereg('int', $field["type"]) && preg_match('~^([0-9]+)(,([0-9]+))?$~', $field["length"], $match) ? ($match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0));
$page = floor(($found_rows - 1) / $limit);
}
- $query = "SELECT" . limit((intval($limit) && $group && count($group) < count($select) && $driver == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . $from . $group_by, ($limit != "" ? intval($limit) : null), ($page ? $limit * $page : 0), "\n");
+ $query = "SELECT" . limit((intval($limit) && $group && count($group) < count($select) && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . $from . $group_by, ($limit != "" ? intval($limit) : null), ($page ? $limit * $page : 0), "\n");
echo $adminer->selectQuery($query);
$result = $connection->query($query);
if (!$result) {
echo "<p class='error'>" . error() . "\n";
} else {
- if ($driver == "mssql") {
+ if ($jush == "mssql") {
$result->seek($limit * $page);
}
$email_fields = array();
// use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
if ($_GET["page"] != "last") {
$found_rows = (intval($limit) && $group && count($group) < count($select)
- ? ($driver == "sql" ? $connection->result(" SELECT FOUND_ROWS()") : $connection->result("SELECT COUNT(*) FROM ($query) x")) // space to allow mysql.trace_mode
+ ? ($jush == "sql" ? $connection->result(" SELECT FOUND_ROWS()") : $connection->result("SELECT COUNT(*) FROM ($query) x")) // space to allow mysql.trace_mode
: count($rows)
);
}
$empty = false;
$q = substr($query, 0, $match[0][1]);
$queries++;
- echo "<pre class='jush-$driver' id='sql-$queries'>" . shorten_utf8(trim($q), 1000) . "</pre>\n";
+ echo "<pre class='jush-$jush' id='sql-$queries'>" . shorten_utf8(trim($q), 1000) . "</pre>\n";
ob_flush();
flush(); // can take a long time - show the running query
$start = explode(" ", microtime()); // microtime(true) is available since PHP 5
print_fieldset("history", lang('History'), $_GET["history"] != "");
foreach ($history as $key => $val) {
//! save and display timestamp
- echo '<a href="' . h(ME . "sql=&history=$key") . '">' . lang('Edit') . "</a> <code class='jush-$driver'>" . shorten_utf8(ltrim(str_replace("\n", " ", str_replace("\r", "", preg_replace('~^(#|-- ).*~m', '', $val)))), 80, "</code>") . "<br>\n";
+ echo '<a href="' . h(ME . "sql=&history=$key") . '">' . lang('Edit') . "</a> <code class='jush-$jush'>" . shorten_utf8(ltrim(str_replace("\n", " ", str_replace("\r", "", preg_replace('~^(#|-- ).*~m', '', $val)))), 80, "</code>") . "<br>\n";
}
echo "<input type='submit' name='clear' value='" . lang('Clear') . "'>\n";
echo "</div></fieldset>\n";
$foreign_keys = foreign_keys($TABLE);
if ($foreign_keys) {
echo "<table cellspacing='0'>\n";
- echo "<thead><tr><th>" . lang('Source') . "<td>" . lang('Target') . "<td>" . lang('ON DELETE') . "<td>" . lang('ON UPDATE') . ($driver != "sqlite" ? "<td> " : "") . "</thead>\n";
+ echo "<thead><tr><th>" . lang('Source') . "<td>" . lang('Target') . "<td>" . lang('ON DELETE') . "<td>" . lang('ON UPDATE') . ($jush != "sqlite" ? "<td> " : "") . "</thead>\n";
foreach ($foreign_keys as $name => $foreign_key) {
$link = ($foreign_key["db"] != "" ? "<strong>" . h($foreign_key["db"]) . "</strong>." : "") . h($foreign_key["table"]);
echo "<tr>";
echo "(<em>" . implode("</em>, <em>", array_map('h', $foreign_key["target"])) . "</em>)";
echo "<td>$foreign_key[on_delete]\n";
echo "<td>$foreign_key[on_update]\n";
- if ($driver != "sqlite") {
+ if ($jush != "sqlite") {
echo '<td><a href="' . h(ME . 'foreign=' . urlencode($TABLE) . '&name=' . urlencode($name)) . '">' . lang('Alter') . '</a>';
}
}
echo "</table>\n";
}
- if ($driver != "sqlite") {
+ if ($jush != "sqlite") {
echo '<p><a href="' . h(ME) . 'foreign=' . urlencode($TABLE) . '">' . lang('Add foreign key') . "</a>\n";
}
}
$timing_event = " $_POST[Timing] $_POST[Event]";
$on = " ON " . idf_escape($TABLE);
$dropped = drop_create(
- "DROP TRIGGER " . idf_escape($_GET["name"]) . ($driver == "pgsql" ? " ON " . idf_escape($TABLE) : ""),
- "CREATE TRIGGER " . idf_escape($_POST["Trigger"]) . ($driver == "mssql" ? $on . $timing_event : $timing_event . $on) . " $_POST[Type]\n$_POST[Statement]",
+ "DROP TRIGGER " . idf_escape($_GET["name"]) . ($jush == "pgsql" ? " ON " . idf_escape($TABLE) : ""),
+ "CREATE TRIGGER " . idf_escape($_POST["Trigger"]) . ($jush == "mssql" ? $on . $timing_event : $timing_event . $on) . " $_POST[Type]\n$_POST[Statement]",
ME . "table=" . urlencode($TABLE),
lang('Trigger has been dropped.'),
lang('Trigger has been altered.'),
echo "<table cellspacing='0'>\n";
foreach ($variables as $key => $val) {
echo "<tr>";
- echo "<th><code class='jush-" . $driver . ($status ? "status" : "set") . "'>" . h($key) . "</code>";
+ echo "<th><code class='jush-" . $jush . ($status ? "status" : "set") . "'>" . h($key) . "</code>";
echo "<td>" . nbsp($val);
}
echo "</table>\n";
return call_user_func($match[2], file_get_contents(dirname(__FILE__) . "/$project/$match[1]"));
}
-$DRIVER = "";
+$driver = "";
if (file_exists(dirname(__FILE__) . "/adminer/drivers/" . $_SERVER["argv"][1] . ".inc.php")) {
- $DRIVER = $_SERVER["argv"][1];
+ $driver = $_SERVER["argv"][1];
array_shift($_SERVER["argv"]);
}
preg_match_all('~\\bfunction ([^(]+)~', file_get_contents($filename), $matches); //! respect context (extension, class)
$functions = array_combine($matches[1], $matches[0]);
unset($functions["__destruct"], $functions["Min_DB"], $functions["Min_Result"]);
-foreach (glob(dirname(__FILE__) . "/adminer/drivers/" . ($DRIVER ? $DRIVER : "*") . ".inc.php") as $filename) {
+foreach (glob(dirname(__FILE__) . "/adminer/drivers/" . ($driver ? $driver : "*") . ".inc.php") as $filename) {
if ($filename != "mysql.inc.php") {
$file = file_get_contents($filename);
foreach ($functions as $val) {
}
}
-$drivers = array();
+include dirname(__FILE__) . "/adminer/include/pdo.inc.php";
foreach (array("adminer", "editor") as $project) {
$lang_ids = array(); // global variable simplifies usage in a callback function
$file = file_get_contents(dirname(__FILE__) . "/$project/index.php");
- if ($DRIVER) {
+ if ($driver) {
$connection = (object) array("server_info" => 5.1); // MySQL support is version specific
- $_GET[$DRIVER] = true; // to load the driver
- include_once dirname(__FILE__) . "/adminer/drivers/$DRIVER.inc.php";
+ $_GET[$driver] = true; // to load the driver
+ include_once dirname(__FILE__) . "/adminer/drivers/$driver.inc.php";
foreach (array("view", "event", "privileges", "user", "processlist", "variables", "trigger", "scheme") as $feature) {
if (!support($feature)) {
$file = str_replace("} elseif (isset(\$_GET[\"$feature\"])) {\n\tinclude \"./$feature.inc.php\";\n", "", $file);
}
$file = preg_replace_callback('~\\b(include|require) "([^"]*)";~', 'put_file', $file);
$file = str_replace('include "../adminer/include/coverage.inc.php";', '', $file);
- if ($DRIVER) {
- $file = preg_replace('(include "../adminer/drivers/(?!' . preg_quote($DRIVER) . ').*\\s*)', '', $file);
+ if ($driver) {
+ $file = preg_replace('(include "../adminer/drivers/(?!' . preg_quote($driver) . ').*\\s*)', '', $file);
}
$file = preg_replace_callback('~\\b(include|require) "([^"]*)";~', 'put_file', $file); // bootstrap.inc.php
$file = preg_replace_callback("~lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])~s", 'lang_ids', $file);
$file = preg_replace("~<\\?php\\s*\\?>\n?|\\?>\n?<\\?php~", '', $file);
$file = php_shrink($file);
- $filename = $project . (preg_match('~-dev$~', $VERSION) ? "" : "-$VERSION") . ($DRIVER ? "-$DRIVER" : "") . ($_SESSION["lang"] ? "-$_SESSION[lang]" : "") . ".php";
+ $filename = $project . (preg_match('~-dev$~', $VERSION) ? "" : "-$VERSION") . ($driver ? "-$driver" : "") . ($_SESSION["lang"] ? "-$_SESSION[lang]" : "") . ".php";
fwrite(fopen($filename, "w"), $file); // file_put_contents() since PHP 5
echo "$filename created (" . strlen($file) . " B).\n";
}