mirror of
https://github.com/vrana/adminer.git
synced 2025-08-17 20:01:25 +02:00
Change directory structure
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@682 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
76
adminer/include/auth.inc.php
Normal file
76
adminer/include/auth.inc.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
$ignore = array("server", "username", "password");
|
||||
$session_name = session_name();
|
||||
if (ini_get("session.use_trans_sid") && isset($_POST[$session_name])) {
|
||||
$ignore[] = $session_name;
|
||||
}
|
||||
if (isset($_POST["server"])) {
|
||||
if (isset($_COOKIE[$session_name]) || isset($_POST[$session_name])) {
|
||||
session_regenerate_id();
|
||||
$_SESSION["usernames"][$_POST["server"]] = $_POST["username"];
|
||||
$_SESSION["passwords"][$_POST["server"]] = $_POST["password"];
|
||||
$_SESSION["tokens"][$_POST["server"]] = rand(1, 1e6);
|
||||
if (count($_POST) == count($ignore)) {
|
||||
$location = ((string) $_GET["server"] === $_POST["server"] ? remove_from_uri() : preg_replace('~^[^?]*/([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"]) . (strlen($_POST["server"]) ? '?server=' . urlencode($_POST["server"]) : ''));
|
||||
if (!isset($_COOKIE[$session_name])) {
|
||||
$location .= (strpos($location, "?") === false ? "?" : "&") . SID;
|
||||
}
|
||||
header("Location: " . (strlen($location) ? $location : "."));
|
||||
exit;
|
||||
}
|
||||
if ($_POST["token"]) {
|
||||
$_POST["token"] = $_SESSION["tokens"][$_POST["server"]];
|
||||
}
|
||||
}
|
||||
$_GET["server"] = $_POST["server"];
|
||||
} elseif (isset($_POST["logout"])) {
|
||||
if ($_POST["token"] != $_SESSION["tokens"][$_GET["server"]]) {
|
||||
page_header(lang('Logout'), lang('Invalid CSRF token. Send the form again.'));
|
||||
page_footer("db");
|
||||
exit;
|
||||
} else {
|
||||
unset($_SESSION["usernames"][$_GET["server"]]);
|
||||
unset($_SESSION["passwords"][$_GET["server"]]);
|
||||
unset($_SESSION["databases"][$_GET["server"]]);
|
||||
unset($_SESSION["tokens"][$_GET["server"]]);
|
||||
unset($_SESSION["history"][$_GET["server"]]);
|
||||
redirect(substr($SELF, 0, -1), lang('Logout successful.'));
|
||||
}
|
||||
}
|
||||
|
||||
function auth_error($exception = null) {
|
||||
global $ignore, $dbh;
|
||||
$username = $_SESSION["usernames"][$_GET["server"]];
|
||||
unset($_SESSION["usernames"][$_GET["server"]]);
|
||||
page_header(lang('Login'), (isset($username) ? htmlspecialchars($exception ? $exception->getMessage() : ($dbh ? $dbh : lang('Invalid credentials.'))) : (isset($_POST["server"]) ? lang('Sessions must be enabled.') : ($_POST ? lang('Session expired, please login again.') : ""))), null);
|
||||
?>
|
||||
<form action="" method="post">
|
||||
<table cellspacing="0">
|
||||
<tr><th><?php echo lang('Server'); ?></th><td><input name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>" /></td></tr>
|
||||
<tr><th><?php echo lang('Username'); ?></th><td><input name="username" value="<?php echo htmlspecialchars($username); ?>" /></td></tr>
|
||||
<tr><th><?php echo lang('Password'); ?></th><td><input type="password" name="password" /></td></tr>
|
||||
</table>
|
||||
<p>
|
||||
<?php
|
||||
hidden_fields($_POST, $ignore); // expired session
|
||||
foreach ($_FILES as $key => $val) {
|
||||
echo '<input type="hidden" name="files[' . htmlspecialchars($key) . ']" value="' . ($val["error"] ? $val["error"] : base64_encode(file_get_contents($val["tmp_name"]))) . '" />';
|
||||
}
|
||||
?>
|
||||
<input type="submit" value="<?php echo lang('Login'); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
<?php
|
||||
page_footer("auth");
|
||||
}
|
||||
|
||||
$username = &$_SESSION["usernames"][$_GET["server"]];
|
||||
if (!isset($username)) {
|
||||
$username = $_GET["username"];
|
||||
}
|
||||
$dbh = (isset($username) ? connect() : '');
|
||||
unset($username);
|
||||
if (is_string($dbh)) {
|
||||
auth_error();
|
||||
exit;
|
||||
}
|
25
adminer/include/connect.inc.php
Normal file
25
adminer/include/connect.inc.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
function connect_error() {
|
||||
global $dbh, $SELF, $VERSION;
|
||||
if (strlen($_GET["db"])) {
|
||||
page_header(lang('Database') . ": " . htmlspecialchars($_GET["db"]), lang('Invalid database.'), false);
|
||||
} else {
|
||||
page_header(lang('Select database'), "", null);
|
||||
echo '<p><a href="' . htmlspecialchars($SELF) . 'database=">' . lang('Create new database') . "</a></p>\n";
|
||||
echo '<p><a href="' . htmlspecialchars($SELF) . 'privileges=">' . lang('Privileges') . "</a></p>\n";
|
||||
echo '<p><a href="' . htmlspecialchars($SELF) . 'processlist=">' . lang('Process list') . "</a></p>\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>") . "</p>\n";
|
||||
echo "<p>" . lang('Logged as: %s', "<b>" . htmlspecialchars($dbh->result($dbh->query("SELECT USER()"))) . "</b>") . "</p>\n";
|
||||
}
|
||||
page_footer("db");
|
||||
}
|
||||
|
||||
$dbh->query("SET SQL_QUOTE_SHOW_CREATE=1");
|
||||
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"]))) {
|
||||
if (strlen($_GET["db"])) {
|
||||
unset($_SESSION["databases"][$_GET["server"]]);
|
||||
}
|
||||
connect_error();
|
||||
exit;
|
||||
}
|
||||
$dbh->query("SET CHARACTER SET utf8");
|
113
adminer/include/design.inc.php
Normal file
113
adminer/include/design.inc.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
|
||||
global $SELF, $LANG, $VERSION;
|
||||
header("Content-Type: text/html; charset=utf-8");
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php echo $LANG; ?>">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
||||
<meta name="robots" content="noindex" />
|
||||
<title><?php echo $title . (strlen($title2) ? ": " . htmlspecialchars($title2) : "") . " - " . lang('Adminer'); ?></title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="default.css<?php // Ondrej Valka, http://valka.info ?>" />
|
||||
<?php if (file_exists("adminer.css")) { ?>
|
||||
<link rel="stylesheet" type="text/css" href="adminer.css" />
|
||||
<?php } ?>
|
||||
</head>
|
||||
|
||||
<body onload="load_jush();<?php echo (isset($_COOKIE["adminer_version"]) ? "" : " verify_version('$VERSION');"); ?>">
|
||||
<script type="text/javascript" src="functions.js"></script>
|
||||
|
||||
<div id="content">
|
||||
<?php
|
||||
if (isset($breadcrumb)) {
|
||||
$link = substr(preg_replace('~db=[^&]*&~', '', $SELF), 0, -1);
|
||||
echo '<p id="breadcrumb"><a href="' . (strlen($link) ? htmlspecialchars($link) : ".") . '">' . (isset($_GET["server"]) ? htmlspecialchars($_GET["server"]) : lang('Server')) . '</a> » ';
|
||||
if (is_array($breadcrumb)) {
|
||||
if (strlen($_GET["db"])) {
|
||||
echo '<a href="' . htmlspecialchars(substr($SELF, 0, -1)) . '">' . htmlspecialchars($_GET["db"]) . '</a> » ';
|
||||
}
|
||||
foreach ($breadcrumb as $key => $val) {
|
||||
if (strlen($val)) {
|
||||
echo '<a href="' . htmlspecialchars("$SELF$key=") . ($key != "privileges" ? urlencode($val) : "") . '">' . htmlspecialchars($val) . '</a> » ';
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "$title</p>\n";
|
||||
}
|
||||
echo "<h2>$title" . (strlen($title2) ? ": " . htmlspecialchars($title2) : "") . "</h2>\n";
|
||||
if ($_SESSION["messages"]) {
|
||||
echo "<p class='message'>" . implode("</p>\n<p class='message'>", $_SESSION["messages"]) . "</p>\n";
|
||||
$_SESSION["messages"] = array();
|
||||
}
|
||||
$databases = &$_SESSION["databases"][$_GET["server"]];
|
||||
if (strlen($_GET["db"]) && $databases && !in_array($_GET["db"], $databases, true)) {
|
||||
$databases = null;
|
||||
}
|
||||
if (isset($databases) && !isset($_GET["sql"]) && !isset($_SESSION["coverage"])) {
|
||||
session_write_close();
|
||||
}
|
||||
if ($error) {
|
||||
echo "<p class='error'>$error</p>\n";
|
||||
}
|
||||
}
|
||||
|
||||
function page_footer($missing = false) {
|
||||
global $SELF, $dbh, $VERSION;
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php switch_lang(); ?>
|
||||
<div id="menu">
|
||||
<h1><a href="http://www.adminer.org/"><?php echo lang('Adminer'); ?></a> <?php echo $VERSION; ?></h1>
|
||||
<div class="version"><a href='http://www.adminer.org/#download' id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? htmlspecialchars($_COOKIE["adminer_version"]) : ""); ?></a></div>
|
||||
<?php if ($missing != "auth") { ?>
|
||||
<form action="" method="post">
|
||||
<p>
|
||||
<a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a>
|
||||
<a href="<?php echo htmlspecialchars($SELF); ?>dump=<?php echo urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]); ?>"><?php echo lang('Dump'); ?></a>
|
||||
<input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]; ?>" />
|
||||
<input type="submit" name="logout" value="<?php echo lang('Logout'); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
<form action="">
|
||||
<p><?php if (strlen($_GET["server"])) { ?><input type="hidden" name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>" /><?php } ?>
|
||||
<?php if (get_databases()) { ?>
|
||||
<select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)</option><?php echo optionlist(get_databases(), $_GET["db"]); ?></select>
|
||||
<?php } else { ?>
|
||||
<input name="db" value="<?php echo htmlspecialchars($_GET["db"]); ?>" /> <input type="submit" value="<?php echo lang('Use'); ?>" />
|
||||
<?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 } ?>
|
||||
<?php if (isset($_GET["dump"])) { ?><input type="hidden" name="dump" value="" /><?php } ?>
|
||||
</p>
|
||||
<?php if (get_databases()) { ?>
|
||||
<noscript><p><input type="submit" value="<?php echo lang('Use'); ?>" /></p></noscript>
|
||||
<?php } ?>
|
||||
</form>
|
||||
<?php
|
||||
if ($missing != "db" && strlen($_GET["db"])) {
|
||||
$result = $dbh->query("SHOW TABLE STATUS");
|
||||
if (!$result->num_rows) {
|
||||
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
|
||||
} else {
|
||||
echo "<p>\n";
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> ';
|
||||
echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Rows"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . htmlspecialchars($row["Name"]) . "</a><br />\n";
|
||||
}
|
||||
echo "</p>\n";
|
||||
}
|
||||
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\n";
|
||||
$result->free();
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
}
|
230
adminer/include/editing.inc.php
Normal file
230
adminer/include/editing.inc.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
function input($name, $field, $value, $separator = "</td><td>") { //! pass empty separator if there are no functions in the whole table
|
||||
global $types;
|
||||
$name = htmlspecialchars(bracket_escape($name));
|
||||
echo "<td" . ($separator ? " class='function'" : "") . ">";
|
||||
if ($field["type"] == "enum") {
|
||||
echo ($separator ? " $separator" : "") . (isset($_GET["select"]) ? ' <label><input type="radio" name="fields[' . $name . ']" value="-1" checked="checked" /><em>' . lang('original') . '</em></label>' : "");
|
||||
if ($field["null"] || isset($_GET["default"])) {
|
||||
echo ' <label><input type="radio" name="fields[' . $name . ']" value=""' . (($field["null"] ? isset($value) : strlen($value)) || isset($_GET["select"]) ? '' : ' checked="checked"') . ' />' . ($field["null"] ? '<em>NULL</em>' : '') . '</label>';
|
||||
}
|
||||
if (!isset($_GET["default"])) {
|
||||
echo '<input type="radio" name="fields[' . $name . ']" value="0"' . ($value === 0 ? ' checked="checked"' : '') . ' />';
|
||||
}
|
||||
preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches);
|
||||
foreach ($matches[1] as $i => $val) {
|
||||
$val = stripcslashes(str_replace("''", "'", $val));
|
||||
$checked = (is_int($value) ? $value == $i+1 : $value === $val);
|
||||
echo ' <label><input type="radio" name="fields[' . $name . ']" value="' . (isset($_GET["default"]) ? (strlen($val) ? htmlspecialchars($val) : " ") : $i+1) . '"' . ($checked ? ' checked="checked"' : '') . ' />' . htmlspecialchars($val) . '</label>';
|
||||
}
|
||||
} else {
|
||||
$first = ($field["null"] || isset($_GET["default"])) + isset($_GET["select"]);
|
||||
$onchange = ($first ? ' onchange="var f = this.form[\'function[' . addcslashes($name, "\r\n'\\") . ']\']; if (' . $first . ' > f.selectedIndex) f.selectedIndex = ' . $first . ';"' : '');
|
||||
$options = array("");
|
||||
if (!isset($_GET["default"])) {
|
||||
if (preg_match('~char|date|time~', $field["type"])) {
|
||||
$options = (preg_match('~char~', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : array("", "now"));
|
||||
}
|
||||
if (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) {
|
||||
if (preg_match('~int|float|double|decimal~', $field["type"])) {
|
||||
$options = array("", "+", "-");
|
||||
}
|
||||
if (preg_match('~date~', $field["type"])) {
|
||||
$options[] = "+ interval";
|
||||
$options[] = "- interval";
|
||||
}
|
||||
if (preg_match('~time~', $field["type"])) {
|
||||
$options[] = "addtime";
|
||||
$options[] = "subtime";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($field["null"] || isset($_GET["default"])) {
|
||||
array_unshift($options, "NULL");
|
||||
}
|
||||
echo (count($options) > 1 || isset($_GET["select"]) ? '<select name="function[' . $name . ']">' . (isset($_GET["select"]) ? '<option value="orig">' . lang('original') . '</option>' : '') . optionlist($options, (isset($value) ? (string) $_POST["function"][$name] : null)) . '</select>' : ($separator ? " " : "")) . $separator;
|
||||
if ($field["type"] == "set") { //! 64 bits
|
||||
preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches);
|
||||
foreach ($matches[1] as $i => $val) {
|
||||
$val = stripcslashes(str_replace("''", "'", $val));
|
||||
$checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true));
|
||||
echo ' <label><input type="checkbox" name="fields[' . $name . '][' . $i . ']" value="' . (isset($_GET["default"]) ? htmlspecialchars($val) : 1 << $i) . '"' . ($checked ? ' checked="checked"' : '') . $onchange . ' />' . htmlspecialchars($val) . '</label>';
|
||||
}
|
||||
} elseif (strpos($field["type"], "text") !== false) {
|
||||
echo '<textarea name="fields[' . $name . ']" cols="50" rows="12"' . $onchange . '>' . htmlspecialchars($value) . '</textarea>';
|
||||
} elseif (preg_match('~binary|blob~', $field["type"])) {
|
||||
echo (ini_get("file_uploads") ? '<input type="file" name="' . $name . '"' . $onchange . ' />' : lang('File uploads are disabled.') . ' ');
|
||||
} else {
|
||||
$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));
|
||||
echo '<input name="fields[' . $name . ']" value="' . htmlspecialchars($value) . '"' . ($maxlength ? " maxlength='$maxlength'" : "") . $onchange . ' />';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function process_input($name, $field) {
|
||||
global $dbh;
|
||||
$idf = bracket_escape($name);
|
||||
$function = $_POST["function"][$idf];
|
||||
$value = $_POST["fields"][$idf];
|
||||
if ($field["type"] == "enum" ? $value == -1 : $function == "orig") {
|
||||
return false;
|
||||
} elseif ($field["type"] == "enum" || $field["auto_increment"] ? !strlen($value) : $function == "NULL") {
|
||||
return "NULL";
|
||||
} elseif ($field["type"] == "enum") {
|
||||
return (isset($_GET["default"]) ? "'" . $dbh->escape_string($value) . "'" : intval($value));
|
||||
} elseif ($field["type"] == "set") {
|
||||
return (isset($_GET["default"]) ? "'" . implode(",", array_map(array($dbh, 'escape_string'), (array) $value)) . "'" : array_sum((array) $value));
|
||||
} elseif (preg_match('~binary|blob~', $field["type"])) {
|
||||
$file = get_file($idf);
|
||||
if (!is_string($file)) {
|
||||
return false; //! report errors
|
||||
}
|
||||
return "_binary'" . (is_string($file) ? $dbh->escape_string($file) : "") . "'";
|
||||
} elseif ($field["type"] == "timestamp" && $value == "CURRENT_TIMESTAMP") {
|
||||
return $value;
|
||||
} elseif (preg_match('~^(now|uuid)$~', $function)) {
|
||||
return "$function()";
|
||||
} elseif (preg_match('~^[+-]$~', $function)) {
|
||||
return idf_escape($name) . " $function '" . $dbh->escape_string($value) . "'";
|
||||
} elseif (preg_match('~^[+-] interval$~', $function)) {
|
||||
return idf_escape($name) . " $function " . (preg_match("~^([0-9]+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : "'" . $dbh->escape_string($value) . "'") . "";
|
||||
} elseif (preg_match('~^(addtime|subtime)$~', $function)) {
|
||||
return "$function(" . idf_escape($name) . ", '" . $dbh->escape_string($value) . "')";
|
||||
} elseif (preg_match('~^(md5|sha1|password)$~', $function)) {
|
||||
return "$function('" . $dbh->escape_string($value) . "')";
|
||||
} else {
|
||||
return "'" . $dbh->escape_string($value) . "'";
|
||||
}
|
||||
}
|
||||
|
||||
function edit_type($key, $field, $collations) {
|
||||
global $types, $unsigned, $inout;
|
||||
?>
|
||||
<td><select name="<?php echo $key; ?>[type]" onchange="editing_type_change(this);"><?php echo optionlist(array_keys($types), $field["type"]); ?></select></td>
|
||||
<td><input name="<?php echo $key; ?>[length]" value="<?php echo htmlspecialchars($field["length"]); ?>" size="3" /></td>
|
||||
<td><?php echo "<select name=\"$key" . '[collation]"' . (preg_match('~char|text|enum|set~', $field["type"]) ? "" : " class='hidden'") . '><option value="">(' . lang('collation') . ')</option>' . optionlist($collations, $field["collation"]) . '</select>' . ($unsigned ? " <select name=\"$key" . '[unsigned]"' . (!$field["type"] || preg_match('~int|float|double|decimal~', $field["type"]) ? "" : " class='hidden'") . '>' . optionlist($unsigned, $field["unsigned"]) . '</select>' : ''); ?></td>
|
||||
<?php
|
||||
}
|
||||
|
||||
function process_type($field, $collate = "COLLATE") {
|
||||
global $dbh, $enum_length, $unsigned;
|
||||
return " $field[type]"
|
||||
. ($field["length"] && !preg_match('~^date|time$~', $field["type"]) ? "(" . process_length($field["length"]) . ")" : "")
|
||||
. (preg_match('~int|float|double|decimal~', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
|
||||
. (preg_match('~char|text|enum|set~', $field["type"]) && $field["collation"] ? " $collate '" . $dbh->escape_string($field["collation"]) . "'" : "")
|
||||
;
|
||||
}
|
||||
|
||||
function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0) {
|
||||
global $inout;
|
||||
$column_comments = false;
|
||||
foreach ($fields as $field) {
|
||||
if (strlen($field["comment"])) {
|
||||
$column_comments = true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<thead><tr>
|
||||
<?php if ($type == "PROCEDURE") { ?><td><?php echo lang('IN-OUT'); ?></td><?php } ?>
|
||||
<th><?php echo ($type == "TABLE" ? lang('Column name') : lang('Parameter name')); ?></th>
|
||||
<td><?php echo lang('Type'); ?></td>
|
||||
<td><?php echo lang('Length'); ?></td>
|
||||
<td><?php echo lang('Options'); ?></td>
|
||||
<?php if ($type == "TABLE") { ?>
|
||||
<td><?php echo lang('NULL'); ?></td>
|
||||
<td><input type="radio" name="auto_increment_col" value="" /><?php echo lang('Auto Increment'); ?></td>
|
||||
<td<?php echo ($column_comments ? "" : " class='hidden'"); ?>><?php echo lang('Comment'); ?></td>
|
||||
<?php } ?>
|
||||
<td><input type="image" name="add[0]" src="plus.gif" alt="+" title="<?php echo lang('Add next'); ?>" /><script type="text/javascript">row_count = <?php echo count($fields); ?>;</script></td>
|
||||
</tr></thead>
|
||||
<?php
|
||||
foreach ($fields as $i => $field) {
|
||||
$i++;
|
||||
$display = (isset($_POST["add"][$i-1]) || (isset($field["field"]) && !$_POST["drop_col"][$i]));
|
||||
?>
|
||||
<tr<?php echo ($display ? "" : " style='display: none;'"); ?>>
|
||||
<?php if ($type == "PROCEDURE") { ?><td><select name="fields[<?php echo $i; ?>][inout]"><?php echo optionlist($inout, $field["inout"]); ?></select></td><?php } ?>
|
||||
<th><?php if ($display) { ?><input name="fields[<?php echo $i; ?>][field]" value="<?php echo htmlspecialchars($field["field"]); ?>" maxlength="64" /><?php } ?><input type="hidden" name="fields[<?php echo $i; ?>][orig]" value="<?php echo htmlspecialchars($field[($_POST ? "orig" : "field")]); ?>" /></th>
|
||||
<?php edit_type("fields[$i]", $field, $collations); ?>
|
||||
<?php if ($type == "TABLE") { ?>
|
||||
<td><input type="checkbox" name="fields[<?php echo $i; ?>][null]" value="1"<?php if ($field["null"]) { ?> checked="checked"<?php } ?> /></td>
|
||||
<td><input type="radio" name="auto_increment_col" value="<?php echo $i; ?>"<?php if ($field["auto_increment"]) { ?> checked="checked"<?php } ?> /></td>
|
||||
<td<?php echo ($column_comments ? "" : " class='hidden'"); ?>><input name="fields[<?php echo $i; ?>][comment]" value="<?php echo htmlspecialchars($field["comment"]); ?>" maxlength="255" /></td>
|
||||
<?php } ?>
|
||||
<?php
|
||||
echo "<td><input type='image' name='add[$i]' src='plus.gif' alt='+' title='" . lang('Add next') . "' onclick='return !editing_add_row(this, $allowed);' />";
|
||||
echo " <input type='image' name='drop_col[$i]' src='cross.gif' alt='x' title='" . lang('Remove') . "' onclick='return !editing_remove_row(this);' />";
|
||||
echo " <input type='image' name='up[$i]' src='up.gif' alt='^' title='" . lang('Move up') . "' />";
|
||||
echo " <input type='image' name='down[$i]' src='down.gif' alt='v' title='" . lang('Move down') . "' />";
|
||||
echo "</td>\n</tr>\n";
|
||||
}
|
||||
return $column_comments;
|
||||
}
|
||||
|
||||
function process_fields(&$fields) {
|
||||
ksort($fields);
|
||||
$offset = 0;
|
||||
if ($_POST["up"]) {
|
||||
$last = 0;
|
||||
foreach ($fields as $key => $field) {
|
||||
if (key($_POST["up"]) == $key) {
|
||||
unset($fields[$key]);
|
||||
array_splice($fields, $last, 0, array($field));
|
||||
break;
|
||||
}
|
||||
if (isset($field["field"])) {
|
||||
$last = $offset;
|
||||
}
|
||||
$offset++;
|
||||
}
|
||||
}
|
||||
if ($_POST["down"]) {
|
||||
$found = false;
|
||||
foreach ($fields as $key => $field) {
|
||||
if (isset($field["field"]) && $found) {
|
||||
unset($fields[key($_POST["down"])]);
|
||||
array_splice($fields, $offset, 0, array($found));
|
||||
break;
|
||||
}
|
||||
if (key($_POST["down"]) == $key) {
|
||||
$found = $field;
|
||||
}
|
||||
$offset++;
|
||||
}
|
||||
}
|
||||
$fields = array_values($fields);
|
||||
if ($_POST["add"]) {
|
||||
array_splice($fields, key($_POST["add"]), 0, array(array()));
|
||||
}
|
||||
}
|
||||
|
||||
function normalize_enum($match) {
|
||||
return "'" . str_replace("'", "''", addcslashes(stripcslashes(str_replace($match[0]{0} . $match[0]{0}, $match[0]{0}, substr($match[0], 1, -1))), '\\')) . "'";
|
||||
}
|
||||
|
||||
function routine($name, $type) {
|
||||
global $dbh, $enum_length, $inout;
|
||||
$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 = "([a-z]+)(?:\\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";
|
||||
$create = $dbh->result($dbh->query("SHOW CREATE $type " . idf_escape($name)), 2);
|
||||
preg_match("~\\(((?:$pattern\\s*,?)*)\\)" . ($type == "FUNCTION" ? "\\s*RETURNS\\s+$type_pattern" : "") . "\\s*(.*)~is", $create, $match);
|
||||
$fields = array();
|
||||
preg_match_all("~$pattern\\s*,?~is", $match[1], $matches, PREG_SET_ORDER);
|
||||
foreach ($matches as $i => $param) {
|
||||
$data_type = strtolower($param[4]);
|
||||
$fields[$i] = array(
|
||||
"field" => str_replace("``", "`", $param[2]) . $param[3],
|
||||
"type" => (isset($aliases[$data_type]) ? $aliases[$data_type] : $data_type),
|
||||
"length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $param[5]),
|
||||
"unsigned" => strtolower(preg_replace('~\\s+~', ' ', trim("$param[7] $param[6]"))),
|
||||
"inout" => strtoupper($param[1]),
|
||||
"collation" => strtolower($param[8]),
|
||||
);
|
||||
}
|
||||
if ($type != "FUNCTION") {
|
||||
return array("fields" => $fields, "definition" => $match[10]);
|
||||
}
|
||||
$returns = array("type" => $match[10], "length" => $match[11], "unsigned" => $match[13], "collation" => $match[14]);
|
||||
return array("fields" => $fields, "returns" => $returns, "definition" => $match[15]);
|
||||
}
|
178
adminer/include/export.inc.php
Normal file
178
adminer/include/export.inc.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
function dump_csv($row) {
|
||||
foreach ($row as $key => $val) {
|
||||
if (preg_match("~[\"\n,]~", $val) || (isset($val) && !strlen($val))) {
|
||||
$row[$key] = '"' . str_replace('"', '""', $val) . '"';
|
||||
}
|
||||
}
|
||||
echo implode(",", $row) . "\n";
|
||||
}
|
||||
|
||||
function dump_table($table, $style, $is_view = false) {
|
||||
global $dbh;
|
||||
if ($_POST["format"] == "csv") {
|
||||
echo "\xef\xbb\xbf";
|
||||
if ($style) {
|
||||
dump_csv(array_keys(fields($table)));
|
||||
}
|
||||
} elseif ($style) {
|
||||
$result = $dbh->query("SHOW CREATE TABLE " . idf_escape($table));
|
||||
if ($result) {
|
||||
if ($style == "DROP+CREATE") {
|
||||
echo "DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . idf_escape($table) . ";\n";
|
||||
}
|
||||
$create = $dbh->result($result, 1);
|
||||
$result->free();
|
||||
echo ($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) {
|
||||
$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->escape_string($table) . "' ORDER BY ORDINAL_POSITION";
|
||||
?>
|
||||
DELIMITER ;;
|
||||
CREATE PROCEDURE adminer_alter () BEGIN
|
||||
DECLARE _column_name, _collation_name, _column_type, after varchar(64) DEFAULT '';
|
||||
DECLARE _column_default longtext;
|
||||
DECLARE _is_nullable char(3);
|
||||
DECLARE _extra varchar(20);
|
||||
DECLARE _column_comment varchar(255);
|
||||
DECLARE done, set_after bool DEFAULT 0;
|
||||
DECLARE add_columns text DEFAULT '<?php
|
||||
$fields = array();
|
||||
$result = $dbh->query($query);
|
||||
$after = "";
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$row["default"] = (isset($row["COLUMN_DEFAULT"]) ? "'" . $dbh->escape_string($row["COLUMN_DEFAULT"]) . "'" : "NULL");
|
||||
$row["after"] = $dbh->escape_string($after); //! rgt AFTER lft, lft AFTER id doesn't work
|
||||
$row["alter"] = $dbh->escape_string(idf_escape($row["COLUMN_NAME"])
|
||||
. " $row[COLUMN_TYPE]"
|
||||
. ($row["COLLATION_NAME"] ? " COLLATE $row[COLLATION_NAME]" : "")
|
||||
. (isset($row["COLUMN_DEFAULT"]) ? " DEFAULT $row[default]" : "")
|
||||
. ($row["IS_NULLABLE"] == "YES" ? "" : " NOT NULL")
|
||||
. ($row["EXTRA"] ? " $row[EXTRA]" : "")
|
||||
. ($row["COLUMN_COMMENT"] ? " COMMENT '" . $dbh->escape_string($row["COLUMN_COMMENT"]) . "'" : "")
|
||||
. ($after ? " AFTER " . idf_escape($after) : " FIRST")
|
||||
);
|
||||
echo ", ADD $row[alter]";
|
||||
$fields[] = $row;
|
||||
$after = $row["COLUMN_NAME"];
|
||||
}
|
||||
$result->free();
|
||||
?>';
|
||||
DECLARE columns CURSOR FOR <?php echo $query; ?>;
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
|
||||
SET @alter_table = '';
|
||||
OPEN columns;
|
||||
REPEAT
|
||||
FETCH columns INTO _column_name, _column_default, _is_nullable, _collation_name, _column_type, _extra, _column_comment;
|
||||
IF NOT done THEN
|
||||
SET set_after = 1;
|
||||
CASE _column_name<?php
|
||||
foreach ($fields as $row) {
|
||||
echo "
|
||||
WHEN '" . $dbh->escape_string($row["COLUMN_NAME"]) . "' THEN
|
||||
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->escape_string($row["COLUMN_COMMENT"]) . "' OR after != '$row[after]' THEN
|
||||
SET @alter_table = CONCAT(@alter_table, ', MODIFY $row[alter]');
|
||||
END IF;"; //! don't replace in comment
|
||||
}
|
||||
?>
|
||||
|
||||
ELSE
|
||||
SET @alter_table = CONCAT(@alter_table, ', DROP ', _column_name);
|
||||
SET set_after = 0;
|
||||
END CASE;
|
||||
IF set_after THEN
|
||||
SET after = _column_name;
|
||||
END IF;
|
||||
END IF;
|
||||
UNTIL done END REPEAT;
|
||||
CLOSE columns;
|
||||
IF @alter_table != '' OR add_columns != '' THEN
|
||||
SET @alter_table = CONCAT('ALTER TABLE <?php echo idf_escape($table); ?>', SUBSTR(CONCAT(add_columns, @alter_table), 2));
|
||||
PREPARE alter_command FROM @alter_table;
|
||||
EXECUTE alter_command;
|
||||
DROP PREPARE alter_command;
|
||||
END IF;
|
||||
END;;
|
||||
DELIMITER ;
|
||||
CALL adminer_alter;
|
||||
DROP PROCEDURE adminer_alter;
|
||||
|
||||
<?php
|
||||
//! indexes
|
||||
}
|
||||
|
||||
if ($dbh->server_info >= 5) {
|
||||
$result = $dbh->query("SHOW TRIGGERS LIKE '" . $dbh->escape_string(addcslashes($table, "%_")) . "'");
|
||||
if ($result->num_rows) {
|
||||
echo "DELIMITER ;;\n\n";
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
echo "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW $row[Statement];;\n\n";
|
||||
}
|
||||
echo "DELIMITER ;\n\n";
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function dump_data($table, $style, $select = "") {
|
||||
global $dbh, $max_packet;
|
||||
if ($style) {
|
||||
if ($_POST["format"] != "csv" && $style == "TRUNCATE+INSERT") {
|
||||
echo "TRUNCATE " . idf_escape($table) . ";\n";
|
||||
}
|
||||
$result = $dbh->query(($select ? $select : "SELECT * FROM " . idf_escape($table))); //! enum and set as numbers, binary as _binary, microtime
|
||||
if ($result) {
|
||||
$length = 0;
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
if ($_POST["format"] == "csv") {
|
||||
dump_csv($row);
|
||||
} else {
|
||||
$insert = "INSERT INTO " . idf_escape($table) . ($select ? " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ")" : "") . " VALUES ";
|
||||
$row2 = array();
|
||||
foreach ($row as $key => $val) {
|
||||
$row2[$key] = (isset($val) ? "'" . $dbh->escape_string($val) . "'" : "NULL");
|
||||
}
|
||||
if ($style == "INSERT+UPDATE") {
|
||||
$set = array();
|
||||
foreach ($row as $key => $val) {
|
||||
$set[] = idf_escape($key) . " = " . (isset($val) ? "'" . $dbh->escape_string($val) . "'" : "NULL");
|
||||
}
|
||||
echo "$insert (" . implode(", ", $row2) . ") ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n";
|
||||
} else {
|
||||
$s = "(" . implode(", ", $row2) . ")";
|
||||
if (!$length) {
|
||||
echo $insert, $s;
|
||||
$length = strlen($insert) + strlen($s);
|
||||
} else {
|
||||
$length += 2 + strlen($s);
|
||||
if ($length < $max_packet) {
|
||||
echo ", ", $s;
|
||||
} else {
|
||||
echo ";\n", $insert, $s;
|
||||
$length = strlen($insert) + strlen($s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($_POST["format"] != "csv" && $style != "INSERT+UPDATE" && $result->num_rows) {
|
||||
echo ";\n";
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function dump_headers($identifier, $multi_table = false) {
|
||||
$filename = (strlen($identifier) ? friendly_url($identifier) : "dump");
|
||||
$ext = ($_POST["format"] == "sql" ? "sql" : ($multi_table ? "tar" : "csv"));
|
||||
header("Content-Type: " . ($ext == "tar" ? "application/x-tar" : ($ext == "sql" || $_POST["output"] != "file" ? "text/plain" : "text/csv")) . "; charset=utf-8");
|
||||
header("Content-Disposition: " . ($_POST["output"] == "file" ? "attachment" : "inline") . "; filename=$filename.$ext");
|
||||
return $ext;
|
||||
}
|
||||
|
||||
$dump_output = "<select name='output'><option value='text'>" . lang('open') . "</option><option value='file'>" . lang('save') . "</option></select>";
|
||||
$dump_format = "<select name='format'><option value='sql'>" . lang('SQL') . "</option><option value='csv'>" . lang('CSV') . "</option></select>";
|
||||
$max_packet = 0;
|
252
adminer/include/functions.inc.php
Normal file
252
adminer/include/functions.inc.php
Normal file
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
function idf_escape($idf) {
|
||||
return "`" . str_replace("`", "``", $idf) . "`";
|
||||
}
|
||||
|
||||
function idf_unescape($idf) {
|
||||
return str_replace("``", "`", $idf);
|
||||
}
|
||||
|
||||
function bracket_escape($idf, $back = false) {
|
||||
static $trans = array(':' => ':1', ']' => ':2', '[' => ':3');
|
||||
return strtr($idf, ($back ? array_flip($trans) : $trans));
|
||||
}
|
||||
|
||||
function optionlist($options, $selected = null) {
|
||||
$return = "";
|
||||
foreach ($options as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$return .= '<optgroup label="' . htmlspecialchars($k) . '">';
|
||||
}
|
||||
foreach ((is_array($v) ? $v : array($v)) as $val) {
|
||||
$return .= '<option' . ($val === $selected ? ' selected="selected"' : '') . '>' . htmlspecialchars($val) . '</option>';
|
||||
}
|
||||
if (is_array($v)) {
|
||||
$return .= '</optgroup>';
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function get_vals($query, $column = 0) {
|
||||
global $dbh;
|
||||
$return = array();
|
||||
$result = $dbh->query($query);
|
||||
if ($result) {
|
||||
while ($row = $result->fetch_row()) {
|
||||
$return[] = $row[$column];
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function unique_idf($row, $indexes) {
|
||||
foreach ($indexes as $index) {
|
||||
if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") {
|
||||
$return = array();
|
||||
foreach ($index["columns"] as $key) {
|
||||
if (!isset($row[$key])) {
|
||||
continue 2;
|
||||
}
|
||||
$return[] = urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($row[$key]);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
$return = array();
|
||||
foreach ($row as $key => $val) {
|
||||
$return[] = (isset($val) ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function where($where) {
|
||||
global $dbh;
|
||||
$return = array();
|
||||
foreach ((array) $where["where"] as $key => $val) {
|
||||
$key = bracket_escape($key, "back");
|
||||
$return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]+|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " = BINARY '" . $dbh->escape_string($val) . "'"; //! enum and set, columns looking like functions
|
||||
}
|
||||
foreach ((array) $where["null"] as $key) {
|
||||
$key = bracket_escape($key, "back");
|
||||
$return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]+|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " IS NULL";
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function where_check($val) {
|
||||
parse_str($val, $check);
|
||||
return where($check);
|
||||
}
|
||||
|
||||
function process_length($length) {
|
||||
global $enum_length;
|
||||
return (preg_match("~^\\s*(?:$enum_length)(?:\\s*,\\s*(?:$enum_length))*\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches) ? implode(",", $matches[0]) : preg_replace('~[^0-9,+-]~', '', $length));
|
||||
}
|
||||
|
||||
function redirect($location, $message = null) {
|
||||
if (isset($message)) {
|
||||
$_SESSION["messages"][] = $message;
|
||||
}
|
||||
if (strlen(SID)) {
|
||||
$location .= (strpos($location, "?") === false ? "?" : "&") . SID;
|
||||
}
|
||||
header("Location: " . (strlen($location) ? $location : "."));
|
||||
exit;
|
||||
}
|
||||
|
||||
function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
|
||||
global $dbh, $error, $SELF;
|
||||
$id = "sql-" . count($_SESSION["messages"]);
|
||||
$sql = "";
|
||||
if ($query) {
|
||||
$sql = " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><span id='$id' class='hidden'><br /><code class='jush-sql'>" . htmlspecialchars($query) . '</code><br /><a href="' . htmlspecialchars($SELF) . 'sql=&history=' . count($_SESSION["history"][$_GET["server"]][$_GET["db"]]) . '">' . lang('Edit') . '</a></span>';
|
||||
$_SESSION["history"][$_GET["server"]][$_GET["db"]][] = $query;
|
||||
}
|
||||
if ($execute) {
|
||||
$failed = !$dbh->query($query);
|
||||
}
|
||||
if ($failed) {
|
||||
$error = htmlspecialchars($dbh->error) . $sql;
|
||||
return false;
|
||||
}
|
||||
if ($redirect) {
|
||||
redirect($location, $message . $sql);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function queries($query = null) {
|
||||
global $dbh;
|
||||
static $queries = array();
|
||||
if (!isset($query)) {
|
||||
return implode(";\n", $queries);
|
||||
}
|
||||
$queries[] = $query;
|
||||
return $dbh->query($query);
|
||||
}
|
||||
|
||||
function remove_from_uri($param = "") {
|
||||
$param = "($param|" . session_name() . ")";
|
||||
return preg_replace("~\\?$param=[^&]*&~", '?', preg_replace("~\\?$param=[^&]*\$|&$param=[^&]*~", '', $_SERVER["REQUEST_URI"]));
|
||||
}
|
||||
|
||||
function print_page($page) {
|
||||
echo " " . ($page == $_GET["page"] ? $page + 1 : '<a href="' . htmlspecialchars(remove_from_uri("page") . ($page ? "&page=$page" : "")) . '">' . ($page + 1) . "</a>");
|
||||
}
|
||||
|
||||
function get_file($key) {
|
||||
if (isset($_POST["files"][$key])) {
|
||||
$length = strlen($_POST["files"][$key]);
|
||||
return ($length && $length < 4 ? intval($_POST["files"][$key]) : base64_decode($_POST["files"][$key]));
|
||||
}
|
||||
return (!$_FILES[$key] || $_FILES[$key]["error"] ? $_FILES[$key]["error"] : file_get_contents($_FILES[$key]["tmp_name"]));
|
||||
}
|
||||
|
||||
function odd($s = ' class="odd"') {
|
||||
static $i = 0;
|
||||
if (!$s) { // reset counter
|
||||
$i = -1;
|
||||
}
|
||||
return ($i++ % 2 ? $s : '');
|
||||
}
|
||||
|
||||
function select($result, $dbh2 = null) {
|
||||
global $SELF;
|
||||
if (!$result->num_rows) {
|
||||
echo "<p class='message'>" . lang('No rows.') . "</p>\n";
|
||||
} else {
|
||||
echo "<table cellspacing='0' class='nowrap'>\n";
|
||||
$links = array();
|
||||
$indexes = array();
|
||||
$columns = array();
|
||||
$blobs = array();
|
||||
$types = array();
|
||||
odd('');
|
||||
for ($i=0; $row = $result->fetch_row(); $i++) {
|
||||
if (!$i) {
|
||||
echo "<thead><tr>";
|
||||
for ($j=0; $j < count($row); $j++) {
|
||||
$field = $result->fetch_field();
|
||||
if (strlen($field->orgtable)) {
|
||||
if (!isset($indexes[$field->orgtable])) {
|
||||
$indexes[$field->orgtable] = array();
|
||||
foreach (indexes($field->orgtable, $dbh2) as $index) {
|
||||
if ($index["type"] == "PRIMARY") {
|
||||
$indexes[$field->orgtable] = array_flip($index["columns"]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$columns[$field->orgtable] = $indexes[$field->orgtable];
|
||||
}
|
||||
if (isset($columns[$field->orgtable][$field->orgname])) {
|
||||
unset($columns[$field->orgtable][$field->orgname]);
|
||||
$indexes[$field->orgtable][$field->orgname] = $j;
|
||||
$links[$j] = $field->orgtable;
|
||||
}
|
||||
}
|
||||
if ($field->charsetnr == 63) {
|
||||
$blobs[$j] = true;
|
||||
}
|
||||
$types[$j] = $field->type;
|
||||
echo "<th>" . htmlspecialchars($field->name) . "</th>";
|
||||
}
|
||||
echo "</tr></thead>\n";
|
||||
}
|
||||
echo "<tr" . odd() . ">";
|
||||
foreach ($row as $key => $val) {
|
||||
if (!isset($val)) {
|
||||
$val = "<i>NULL</i>";
|
||||
} else {
|
||||
if ($blobs[$key] && !is_utf8($val)) {
|
||||
$val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>"; //! link to download
|
||||
} elseif (!strlen(trim($val))) {
|
||||
$val = " ";
|
||||
} else {
|
||||
$val = nl2br(htmlspecialchars($val));
|
||||
if ($types[$key] == 254) {
|
||||
$val = "<code>$val</code>";
|
||||
}
|
||||
}
|
||||
if (isset($links[$key]) && !$columns[$links[$key]]) {
|
||||
$link = "edit=" . urlencode($links[$key]);
|
||||
foreach ($indexes[$links[$key]] as $col => $j) {
|
||||
$link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]);
|
||||
}
|
||||
$val = '<a href="' . htmlspecialchars($SELF) . $link . '">' . $val . '</a>';
|
||||
}
|
||||
}
|
||||
echo "<td>$val</td>";
|
||||
}
|
||||
echo "</tr>\n";
|
||||
}
|
||||
echo "</table>\n";
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
|
||||
function is_utf8($val) {
|
||||
return (preg_match('~~u', $val) && !preg_match('~[\\0-\\x8\\xB\\xC\\xE-\\x1F]~', $val));
|
||||
}
|
||||
|
||||
function shorten_utf8($string, $length) {
|
||||
preg_match("~^(.{0,$length})(.?)~su", $string, $match);
|
||||
return nl2br(htmlspecialchars($match[1])) . ($match[2] ? "<em>...</em>" : "");
|
||||
}
|
||||
|
||||
function friendly_url($val) {
|
||||
return preg_replace('~[^a-z0-9_]~i', '-', $val);
|
||||
}
|
||||
|
||||
function hidden_fields($process, $ignore = array()) {
|
||||
while (list($key, $val) = each($process)) {
|
||||
if (is_array($val)) {
|
||||
foreach ($val as $k => $v) {
|
||||
$process[$key . "[$k]"] = $v;
|
||||
}
|
||||
} elseif (!in_array($key, $ignore)) {
|
||||
echo '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />';
|
||||
}
|
||||
}
|
||||
}
|
68
adminer/include/lang.inc.php
Normal file
68
adminer/include/lang.inc.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
$langs = array(
|
||||
'en' => 'English', // Jakub Vrána - http://php.vrana.cz
|
||||
'cs' => 'Čeština', // Jakub Vrána - http://php.vrana.cz
|
||||
'sk' => 'Slovenčina', // Ivan Suchy - http://www.ivansuchy.com
|
||||
'nl' => 'Nederlands', // Maarten Balliauw - http://blog.maartenballiauw.be
|
||||
'es' => 'Español', // Klemens Häckel - http://clickdimension.wordpress.com
|
||||
'de' => 'Deutsch', // Klemens Häckel - http://clickdimension.wordpress.com
|
||||
'zh' => '简体中文', // Mr. Lodar
|
||||
'fr' => 'Français', // Francis Gagné
|
||||
'it' => 'Italiano', // Alessandro Fiorotto, Paolo Asperti
|
||||
'et' => 'Eesti', // Priit Kallas
|
||||
'ru' => 'Русский язык', // Juraj Hajdúch
|
||||
);
|
||||
|
||||
function lang($idf, $number = null) {
|
||||
global $LANG, $translations;
|
||||
$translation = $translations[$idf];
|
||||
if (is_array($translation) && $translation) {
|
||||
$pos = ($number == 1 ? 0 : ((!$number || $number >= 5) && ereg('cs|sk|ru', $LANG) ? 2 : 1));
|
||||
$translation = $translation[$pos];
|
||||
}
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
return vsprintf((isset($translation) ? $translation : $idf), $args);
|
||||
}
|
||||
|
||||
function switch_lang() {
|
||||
global $LANG, $langs;
|
||||
echo "<form action=''>\n<div id='lang'>";
|
||||
hidden_fields($_GET, array('lang'));
|
||||
echo lang('Language') . ": <select name='lang' onchange='this.form.submit();'>";
|
||||
foreach ($langs as $lang => $val) {
|
||||
echo "<option value='$lang'" . ($LANG == $lang ? " selected='selected'" : "") . ">$val</option>";
|
||||
}
|
||||
echo "</select>\n<noscript><div style='display: inline;'><input type='submit' value='" . lang('Use') . "' /></div></noscript>\n</div>\n</form>\n";
|
||||
}
|
||||
|
||||
if (isset($_GET["lang"])) {
|
||||
$_COOKIE["lang"] = $_GET["lang"];
|
||||
$_SESSION["lang"] = $_GET["lang"];
|
||||
}
|
||||
|
||||
$LANG = "en";
|
||||
if (isset($langs[$_COOKIE["lang"]])) {
|
||||
setcookie("lang", $_GET["lang"], strtotime("+1 month"), preg_replace('~\\?.*~', '', $_SERVER["REQUEST_URI"]));
|
||||
$LANG = $_COOKIE["lang"];
|
||||
} elseif (isset($langs[$_SESSION["lang"]])) {
|
||||
$LANG = $_SESSION["lang"];
|
||||
} else {
|
||||
$accept_language = array();
|
||||
preg_match_all('~([-a-z_]+)(;q=([0-9.]+))?~', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]), $matches, PREG_SET_ORDER);
|
||||
foreach ($matches as $match) {
|
||||
$accept_language[str_replace("_", "-", $match[1])] = (isset($match[3]) ? $match[3] : 1);
|
||||
}
|
||||
arsort($accept_language);
|
||||
foreach ($accept_language as $key => $q) {
|
||||
if (isset($langs[$key])) {
|
||||
$LANG = $key;
|
||||
break;
|
||||
}
|
||||
$key = preg_replace('~-.*~', '', $key);
|
||||
if (!isset($accept_language[$key]) && isset($langs[$key])) {
|
||||
$LANG = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
317
adminer/include/mysql.inc.php
Normal file
317
adminer/include/mysql.inc.php
Normal file
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
if (extension_loaded("mysqli")) {
|
||||
class Min_DB extends MySQLi {
|
||||
var $extension = "MySQLi";
|
||||
|
||||
function Min_DB() {
|
||||
parent::init();
|
||||
}
|
||||
|
||||
function connect($server, $username, $password) {
|
||||
list($host, $port) = explode(":", $server, 2);
|
||||
return @$this->real_connect(
|
||||
(strlen($server) ? $host : ini_get("mysqli.default_host")),
|
||||
(strlen("$server$username") ? $username : ini_get("mysqli.default_user")),
|
||||
(strlen("$server$username$password") ? $password : ini_get("mysqli.default_pw")),
|
||||
null,
|
||||
(is_numeric($port) ? $port : ini_get("mysqli.default_port")),
|
||||
(!is_numeric($port) ? $port : null)
|
||||
);
|
||||
}
|
||||
|
||||
function result($result, $field = 0) {
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
$row = $result->_result->fetch_array();
|
||||
return $row[$field];
|
||||
}
|
||||
|
||||
// minification compatibility start
|
||||
function select_db($database) {
|
||||
return parent::select_db($database);
|
||||
}
|
||||
|
||||
function query($query) {
|
||||
$result = parent::query($query);
|
||||
return (is_object($result) ? new Min_Result($result) : $result);
|
||||
}
|
||||
|
||||
function multi_query($query) {
|
||||
return parent::multi_query($query);
|
||||
}
|
||||
|
||||
function store_result() {
|
||||
$result = parent::store_result();
|
||||
return (is_object($result) ? new Min_Result($result) : $result);
|
||||
}
|
||||
|
||||
function next_result() {
|
||||
return parent::next_result();
|
||||
}
|
||||
|
||||
function escape_string($string) {
|
||||
return parent::escape_string($string);
|
||||
}
|
||||
}
|
||||
|
||||
class Min_Result {
|
||||
var $_result, $num_rows;
|
||||
|
||||
function __construct($result) {
|
||||
$this->_result = $result;
|
||||
$this->num_rows = $result->num_rows;
|
||||
}
|
||||
|
||||
function fetch_assoc() {
|
||||
return $this->_result->fetch_assoc();
|
||||
}
|
||||
|
||||
function fetch_row() {
|
||||
return $this->_result->fetch_row();
|
||||
}
|
||||
|
||||
function fetch_field() {
|
||||
return $this->_result->fetch_field();
|
||||
}
|
||||
|
||||
function free() {
|
||||
return $this->_result->free();
|
||||
}
|
||||
// minification compatibility end
|
||||
}
|
||||
|
||||
} elseif (extension_loaded("mysql")) {
|
||||
class Min_DB {
|
||||
var $extension = "MySQL", $_link, $_result, $server_info, $affected_rows, $error;
|
||||
|
||||
function connect($server, $username, $password) {
|
||||
$this->_link = @mysql_connect(
|
||||
(strlen($server) ? $server : ini_get("mysql.default_host")),
|
||||
(strlen("$server$username") ? $username : ini_get("mysql.default_user")),
|
||||
(strlen("$server$username$password") ? $password : ini_get("mysql.default_password")),
|
||||
true,
|
||||
131072 // CLIENT_MULTI_RESULTS for CALL
|
||||
);
|
||||
if ($this->_link) {
|
||||
$this->server_info = mysql_get_server_info($this->_link);
|
||||
} else {
|
||||
$this->error = mysql_error();
|
||||
}
|
||||
return (bool) $this->_link;
|
||||
}
|
||||
|
||||
function select_db($database) {
|
||||
return mysql_select_db($database, $this->_link);
|
||||
}
|
||||
|
||||
function query($query) {
|
||||
$result = @mysql_query($query, $this->_link); // mute mysql.trace_mode
|
||||
if (!$result) {
|
||||
$this->error = mysql_error($this->_link);
|
||||
return false;
|
||||
} elseif ($result === true) {
|
||||
$this->affected_rows = mysql_affected_rows($this->_link);
|
||||
return true;
|
||||
}
|
||||
return new Min_Result($result);
|
||||
}
|
||||
|
||||
function multi_query($query) {
|
||||
return $this->_result = $this->query($query);
|
||||
}
|
||||
|
||||
function store_result() {
|
||||
return $this->_result;
|
||||
}
|
||||
|
||||
function next_result() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function result($result, $field = 0) {
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
return mysql_result($result->_result, 0, $field);
|
||||
}
|
||||
|
||||
function escape_string($string) {
|
||||
return mysql_real_escape_string($string, $this->_link);
|
||||
}
|
||||
}
|
||||
|
||||
class Min_Result {
|
||||
var $_result, $_offset = 0, $num_rows;
|
||||
|
||||
function Min_Result($result) {
|
||||
$this->_result = $result;
|
||||
$this->num_rows = mysql_num_rows($result);
|
||||
}
|
||||
|
||||
function fetch_assoc() {
|
||||
return mysql_fetch_assoc($this->_result);
|
||||
}
|
||||
|
||||
function fetch_row() {
|
||||
return mysql_fetch_row($this->_result);
|
||||
}
|
||||
|
||||
function fetch_field() {
|
||||
$row = mysql_fetch_field($this->_result, $this->_offset++);
|
||||
$row->orgtable = $row->table;
|
||||
$row->orgname = $row->name;
|
||||
$row->charsetnr = ($row->blob ? 63 : 0);
|
||||
return $row;
|
||||
}
|
||||
|
||||
function free() {
|
||||
return mysql_free_result($this->_result);
|
||||
}
|
||||
}
|
||||
|
||||
} elseif (extension_loaded("pdo_mysql")) {
|
||||
class Min_DB extends Min_PDO {
|
||||
var $extension = "PDO_MySQL";
|
||||
|
||||
function connect($server, $username, $password) {
|
||||
$this->dsn("mysql:host=" . str_replace(":", ";unix_socket=", preg_replace('~:([0-9])~', ';port=\\1', $server)), $username, $password);
|
||||
$this->server_info = $this->result($this->query("SELECT VERSION()"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
page_header(lang('No MySQL extension'), lang('None of supported PHP extensions (%s) are available.', 'MySQLi, MySQL, PDO_MySQL'), null);
|
||||
page_footer("auth");
|
||||
exit;
|
||||
}
|
||||
|
||||
$types = array(
|
||||
"tinyint" => 3, "smallint" => 5, "mediumint" => 8, "int" => 10, "bigint" => 20,
|
||||
"float" => 12, "double" => 21, "decimal" => 66,
|
||||
"date" => 10, "datetime" => 19, "timestamp" => 19, "time" => 10, "year" => 4,
|
||||
"char" => 255, "varchar" => 65535,
|
||||
"binary" => 255, "varbinary" => 65535,
|
||||
"tinytext" => 255, "text" => 65535, "mediumtext" => 16777215, "longtext" => 4294967295,
|
||||
"tinyblob" => 255, "blob" => 65535, "mediumblob" => 16777215, "longblob" => 4294967295,
|
||||
"enum" => 65535, "set" => 64,
|
||||
);
|
||||
$unsigned = array("", "unsigned", "zerofill", "unsigned zerofill");
|
||||
|
||||
function connect() {
|
||||
$dbh = new Min_DB;
|
||||
return ($dbh->connect($_GET["server"], $_SESSION["usernames"][$_GET["server"]], $_SESSION["passwords"][$_GET["server"]]) ? $dbh : $dbh->error);
|
||||
}
|
||||
|
||||
function get_databases() {
|
||||
$return = &$_SESSION["databases"][$_GET["server"]];
|
||||
if (!isset($return)) {
|
||||
flush();
|
||||
$return = get_vals("SHOW DATABASES");
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function table_status($table) {
|
||||
global $dbh;
|
||||
$result = $dbh->query("SHOW TABLE STATUS LIKE '" . $dbh->escape_string(addcslashes($table, "%_")) . "'");
|
||||
$return = $result->fetch_assoc();
|
||||
$result->free();
|
||||
return $return;
|
||||
}
|
||||
|
||||
function fields($table) {
|
||||
global $dbh;
|
||||
$return = array();
|
||||
$result = $dbh->query("SHOW FULL COLUMNS FROM " . idf_escape($table));
|
||||
if ($result) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
preg_match('~^([^( ]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
|
||||
$return[$row["Field"]] = array(
|
||||
"field" => $row["Field"],
|
||||
"type" => $match[1],
|
||||
"length" => $match[2],
|
||||
"unsigned" => ltrim($match[3] . $match[4]),
|
||||
"default" => (strlen($row["Default"]) || ereg("char", $match[1]) ? $row["Default"] : null),
|
||||
"null" => ($row["Null"] == "YES"),
|
||||
"auto_increment" => ($row["Extra"] == "auto_increment"),
|
||||
"collation" => $row["Collation"],
|
||||
"privileges" => array_flip(explode(",", $row["Privileges"])),
|
||||
"comment" => $row["Comment"],
|
||||
"primary" => ($row["Key"] == "PRI"),
|
||||
);
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function indexes($table, $dbh2 = null) {
|
||||
global $dbh;
|
||||
if (!is_object($dbh2)) {
|
||||
$dbh2 = $dbh;
|
||||
}
|
||||
$return = array();
|
||||
$result = $dbh2->query("SHOW INDEX FROM " . idf_escape($table));
|
||||
if ($result) {
|
||||
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"]]["columns"][$row["Seq_in_index"]] = $row["Column_name"];
|
||||
$return[$row["Key_name"]]["lengths"][$row["Seq_in_index"]] = $row["Sub_part"];
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function foreign_keys($table) {
|
||||
global $dbh, $on_actions;
|
||||
static $pattern = '(?:[^`]+|``)+';
|
||||
$return = array();
|
||||
$result = $dbh->query("SHOW CREATE TABLE " . idf_escape($table));
|
||||
if ($result) {
|
||||
$create_table = $dbh->result($result, 1);
|
||||
$result->free();
|
||||
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) {
|
||||
preg_match_all("~`($pattern)`~", $match[2], $source);
|
||||
preg_match_all("~`($pattern)`~", $match[5], $target);
|
||||
$return[$match[1]] = array(
|
||||
"db" => idf_unescape(strlen($match[4]) ? $match[3] : $match[4]),
|
||||
"table" => idf_unescape(strlen($match[4]) ? $match[4] : $match[3]),
|
||||
"source" => array_map('idf_unescape', $source[1]),
|
||||
"target" => array_map('idf_unescape', $target[1]),
|
||||
"on_delete" => $match[6],
|
||||
"on_update" => $match[7],
|
||||
);
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function view($name) {
|
||||
global $dbh;
|
||||
return array("select" => preg_replace('~^(?:[^`]+|`[^`]*`)* AS ~U', '', $dbh->result($dbh->query("SHOW CREATE VIEW " . idf_escape($name)), 1)));
|
||||
}
|
||||
|
||||
function collations() {
|
||||
global $dbh;
|
||||
$return = array();
|
||||
$result = $dbh->query("SHOW COLLATION");
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
if ($row["Default"] && $return[$row["Charset"]]) {
|
||||
array_unshift($return[$row["Charset"]], $row["Collation"]);
|
||||
} else {
|
||||
$return[$row["Charset"]][] = $row["Collation"];
|
||||
}
|
||||
}
|
||||
$result->free();
|
||||
return $return;
|
||||
}
|
||||
|
||||
function table_comment(&$row) {
|
||||
if ($row["Engine"] == "InnoDB") {
|
||||
$row["Comment"] = preg_replace('~(?:(.+); )?InnoDB free: .*~', '\\1', $row["Comment"]);
|
||||
}
|
||||
}
|
84
adminer/include/pdo.inc.php
Normal file
84
adminer/include/pdo.inc.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
if (extension_loaded('pdo')) {
|
||||
class Min_PDO extends PDO {
|
||||
var $_result, $server_info, $affected_rows, $error;
|
||||
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function dsn($dsn, $username, $password) {
|
||||
set_exception_handler('auth_error'); // try/catch is not compatible with PHP 4
|
||||
parent::__construct($dsn, $username, $password);
|
||||
restore_exception_handler();
|
||||
$this->setAttribute(13, array('Min_PDOStatement')); // PDO::ATTR_STATEMENT_CLASS
|
||||
}
|
||||
|
||||
function select_db($database) {
|
||||
return $this->query("USE " . idf_escape($database));
|
||||
}
|
||||
|
||||
function query($query) {
|
||||
$result = parent::query($query);
|
||||
if (!$result) {
|
||||
$errorInfo = $this->errorInfo();
|
||||
$this->error = $errorInfo[2];
|
||||
return false;
|
||||
}
|
||||
$this->_result = $result;
|
||||
if (!$result->columnCount()) {
|
||||
$this->affected_rows = $result->rowCount();
|
||||
return true;
|
||||
}
|
||||
$result->num_rows = $result->rowCount();
|
||||
return $result;
|
||||
}
|
||||
|
||||
function multi_query($query) {
|
||||
return $this->query($query);
|
||||
}
|
||||
|
||||
function store_result() {
|
||||
return ($this->_result->columnCount() ? $this->_result : true);
|
||||
}
|
||||
|
||||
function next_result() {
|
||||
return $this->_result->nextRowset();
|
||||
}
|
||||
|
||||
function result($result, $field = 0) {
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
$row = $result->fetch();
|
||||
return $row[$field];
|
||||
}
|
||||
|
||||
function escape_string($string) {
|
||||
return substr($this->quote($string), 1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
class Min_PDOStatement extends PDOStatement {
|
||||
var $_offset = 0, $num_rows;
|
||||
|
||||
function fetch_assoc() {
|
||||
return $this->fetch(2); // PDO::FETCH_ASSOC
|
||||
}
|
||||
|
||||
function fetch_row() {
|
||||
return $this->fetch(3); // PDO::FETCH_NUM
|
||||
}
|
||||
|
||||
function fetch_field() {
|
||||
$row = (object) $this->getColumnMeta($this->_offset++);
|
||||
$row->orgtable = $row->table;
|
||||
$row->orgname = $row->name;
|
||||
$row->charsetnr = (in_array("blob", $row->flags) ? 63 : 0);
|
||||
return $row;
|
||||
}
|
||||
|
||||
function free() {
|
||||
// $this->__destruct() is not callable
|
||||
}
|
||||
}
|
||||
}
|
264
adminer/include/sqlite.inc.php
Normal file
264
adminer/include/sqlite.inc.php
Normal file
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
|
||||
if ($_GET["sqlite_version"] == 2) {
|
||||
|
||||
class Min_SQLite extends SQLiteDatabase {
|
||||
var $extension = "SQLite";
|
||||
|
||||
function open($filename) {
|
||||
parent::__construct($filename);
|
||||
}
|
||||
|
||||
function query($query) {
|
||||
$result = @parent::query($query, SQLITE_BOTH, $error);
|
||||
if (!$result) {
|
||||
$this->error = $error;
|
||||
return false;
|
||||
} elseif ($result === true) {
|
||||
$this->affected_rows = parent::changes();
|
||||
return true;
|
||||
}
|
||||
return new Min_Result($result);
|
||||
}
|
||||
|
||||
function escape_string($string) {
|
||||
return sqlite_escape_string($string);
|
||||
}
|
||||
|
||||
function result($result, $field = 0) {
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
$row = $result->_result->fetch();
|
||||
return $row[$field];
|
||||
}
|
||||
}
|
||||
|
||||
class Min_Result {
|
||||
var $_result, $num_rows;
|
||||
|
||||
function __construct($result) {
|
||||
$this->_result = $result;
|
||||
$this->num_rows = $result->numRows();
|
||||
}
|
||||
|
||||
function fetch_assoc() {
|
||||
return $this->_result->fetch(SQLITE_ASSOC);
|
||||
}
|
||||
|
||||
function fetch_row() {
|
||||
return $this->_result->fetch(SQLITE_NUM);
|
||||
}
|
||||
|
||||
function fetch_field() {
|
||||
static $column = -1;
|
||||
$column++;
|
||||
return (object) array(
|
||||
"name" => parent::fieldName($column),
|
||||
//! type, orgtable, charsetnr
|
||||
);
|
||||
}
|
||||
|
||||
function free() {
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
class Min_SQLite extends SQLite3 {
|
||||
var $extension = "SQLite3";
|
||||
|
||||
function open($filename) {
|
||||
parent::__construct($filename);
|
||||
}
|
||||
|
||||
function query($query) {
|
||||
$result = @parent::query($query);
|
||||
if (!$result) {
|
||||
$this->error = parent::lastErrorMsg();
|
||||
return false;
|
||||
} elseif ($result === true) {
|
||||
$this->affected_rows = parent::changes();
|
||||
return true;
|
||||
}
|
||||
return new Min_Result($result);
|
||||
}
|
||||
|
||||
function escape_string($string) {
|
||||
return parent::escapeString($string);
|
||||
}
|
||||
|
||||
function result($result, $field = 0) {
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
$row = $result->_result->fetchArray();
|
||||
return $row[$field];
|
||||
}
|
||||
}
|
||||
|
||||
class Min_Result {
|
||||
var $_result, $num_rows;
|
||||
|
||||
function __construct($result) {
|
||||
$this->_result = $result;
|
||||
//! $this->num_rows = ;
|
||||
}
|
||||
|
||||
function fetch_assoc() {
|
||||
return $this->_result->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
function fetch_row() {
|
||||
return $this->_result->fetchArray(SQLITE3_NUM);
|
||||
}
|
||||
|
||||
function fetch_field() {
|
||||
static $column = -1;
|
||||
$column++;
|
||||
return (object) array(
|
||||
"name" => parent::columnName($column),
|
||||
"type" => parent::columnType($column),
|
||||
//! orgtable, charsetnr
|
||||
);
|
||||
}
|
||||
|
||||
function free() {
|
||||
return $this->_result->finalize();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Min_DB extends Min_SQLite {
|
||||
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function select_db($filename) {
|
||||
set_exception_handler('connect_error'); // try/catch is not compatible with PHP 4
|
||||
$this->open($filename);
|
||||
restore_exception_handler();
|
||||
$this->server_info = $this->result($this->query("SELECT sqlite_version()"));
|
||||
return true;
|
||||
}
|
||||
|
||||
function multi_query($query) {
|
||||
return $this->_result = $this->query($query);
|
||||
}
|
||||
|
||||
function store_result() {
|
||||
return $this->_result;
|
||||
}
|
||||
|
||||
function next_result() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} elseif (extension_loaded("pdo_sqlite")) {
|
||||
class Min_DB extends Min_PDO {
|
||||
var $extension = "PDO_SQLite";
|
||||
|
||||
function select_db($filename) {
|
||||
set_exception_handler('connect_error'); // try/catch is not compatible with PHP 4
|
||||
parent::__construct(($_GET["sqlite_version"] == 2 ? "sqlite2" : "sqlite") . ":$filename");
|
||||
restore_exception_handler();
|
||||
$this->setAttribute(13, array('Min_PDOStatement')); // PDO::ATTR_STATEMENT_CLASS
|
||||
$this->server_info = $this->result($this->query("SELECT sqlite_version()"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$types = array("text" => 0, "numeric" => 0, "integer" => 0, "real" => 0, "blob" => 0);
|
||||
$unsigned = array();
|
||||
|
||||
function connect() {
|
||||
return new Min_DB;
|
||||
}
|
||||
|
||||
function get_databases() {
|
||||
return array();
|
||||
}
|
||||
|
||||
function table_status($table) {
|
||||
return array();
|
||||
}
|
||||
|
||||
function fields($table) {
|
||||
global $dbh;
|
||||
$return = array();
|
||||
$result = $dbh->query("PRAGMA table_info(" . idf_escape($table) . ")");
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
preg_match('~^([^( ]+)(?:\\((.+)\\))?$~', $row["Type"], $match);
|
||||
$return[$row["Field"]] = array(
|
||||
"field" => $row["name"],
|
||||
"type" => $match[1],
|
||||
"length" => $match[2],
|
||||
"default" => $row["dflt_value"],
|
||||
"null" => !$row["notnull"],
|
||||
"auto_increment" => false, //!
|
||||
"collation" => $row["Collation"], //!
|
||||
"comment" => "", //!
|
||||
"primary" => $row["pk"],
|
||||
);
|
||||
}
|
||||
$result->free();
|
||||
return $return;
|
||||
}
|
||||
|
||||
function indexes($table, $dbh2 = null) {
|
||||
global $dbh;
|
||||
$return = array();
|
||||
$result = $dbh->query("PRAGMA index_list(" . idf_escape($table) . ")");
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$return[$row["name"]]["type"] = ($row["unique"] ? "UNIQUE" : "INDEX");
|
||||
$result1 = $dbh->query("PRAGMA index_info(" . idf_escape($row["name"]) . ")");
|
||||
while ($row1 = $result1->fetch_assoc()) {
|
||||
$return[$row["name"]]["columns"][$row1["seqno"]] = $row1["name"];
|
||||
}
|
||||
$result1->free();
|
||||
}
|
||||
$result->free();
|
||||
//! detect primary key from table definition
|
||||
return $return;
|
||||
}
|
||||
|
||||
function foreign_keys($table) {
|
||||
global $dbh, $on_actions;
|
||||
static $pattern = '(?:[^`]+|``)+';
|
||||
$return = array();
|
||||
$result = $dbh->query("SHOW CREATE TABLE " . idf_escape($table));
|
||||
if ($result) {
|
||||
$create_table = $dbh->result($result, 1);
|
||||
$result->free();
|
||||
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) {
|
||||
preg_match_all("~`($pattern)`~", $match[2], $source);
|
||||
preg_match_all("~`($pattern)`~", $match[5], $target);
|
||||
$return[$match[1]] = array(
|
||||
"db" => idf_unescape(strlen($match[4]) ? $match[3] : $match[4]),
|
||||
"table" => idf_unescape(strlen($match[4]) ? $match[4] : $match[3]),
|
||||
"source" => array_map('idf_unescape', $source[1]),
|
||||
"target" => array_map('idf_unescape', $target[1]),
|
||||
"on_delete" => $match[6],
|
||||
"on_update" => $match[7],
|
||||
);
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function view($name) {
|
||||
global $dbh;
|
||||
return array("select" => preg_replace('~^(?:[^`]+|`[^`]*`)* AS ~iU', '', $dbh->result($dbh->query("SELECT sql FROM sqlite_master WHERE name = '" . $dbh->escape_string($name) . "'"), 0)));
|
||||
}
|
||||
|
||||
function collations() {
|
||||
return get_vals("PRAGMA collation_list", 1);
|
||||
}
|
||||
|
||||
function table_comment(&$row) {
|
||||
}
|
2
adminer/include/version.inc.php
Normal file
2
adminer/include/version.inc.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$VERSION = "1.11.0-dev";
|
Reference in New Issue
Block a user