git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@65 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2007-07-06 13:03:13 +00:00
parent 4e620135ed
commit ffcea8b587
4 changed files with 190 additions and 157 deletions

View file

@ -16,19 +16,29 @@ function dump($db) {
}
}
echo "CREATE DATABASE IF NOT EXISTS " . idf_escape($db) . ";\n";
$result = mysql_query("SHOW CREATE DATABASE " . idf_escape($db));
if ($result) {
echo mysql_result($result, 0) . ";\n";
mysql_free_result($result);
}
echo "USE " . idf_escape($db) . ";\n";
echo "SET CHARACTER SET utf8;\n\n";
$result = mysql_query("SHOW TABLES");
while ($row = mysql_fetch_row($result)) {
echo mysql_result(mysql_query("SHOW CREATE TABLE " . idf_escape($row[0])), 0, 1) . ";\n";
$result1 = mysql_query("SHOW CREATE TABLE " . idf_escape($row[0]));
if ($result1) {
echo mysql_result($result1, 0, 1) . ";\n";
mysql_free_result($result1);
$result1 = mysql_query("SELECT * FROM " . idf_escape($row[0])); //! except views //! enum and set as numbers
if ($result1) {
while ($row1 = mysql_fetch_row($result1)) {
echo "INSERT INTO " . idf_escape($row[0]) . " VALUES ('" . implode("', '", array_map('mysql_real_escape_string', $row1)) . "');\n";
}
mysql_free_result($result1);
}
echo "\n";
}
}
mysql_free_result($result);
$result = mysql_query("SHOW TRIGGERS");
@ -36,6 +46,7 @@ function dump($db) {
echo "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW $row[Statement];\n\n"; //! delimiter
}
mysql_free_result($result);
echo "\n\n";
echo implode("", (array) $routines[$db]);
}

View file

@ -32,6 +32,7 @@ function optionlist($options, $selected = array(), $not_vals = false) {
function fields($table) {
$return = array();
$result = mysql_query("SHOW FULL COLUMNS FROM " . idf_escape($table));
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
preg_match('~^([^(]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
$return[$row["Field"]] = array(
@ -43,9 +44,11 @@ function fields($table) {
"null" => ($row["Null"] != "NO"),
"extra" => $row["Extra"],
"collation" => $row["Collation"],
"privileges" => explode(",", $row["Privileges"]),
);
}
mysql_free_result($result);
}
return $return;
}
@ -63,13 +66,17 @@ function indexes($table) {
function foreign_keys($table) {
static $pattern = '~`((?:[^`]*|``)+)`~';
$return = array();
$create_table = mysql_result(mysql_query("SHOW CREATE TABLE " . idf_escape($table)), 0, 1);
$result = mysql_query("SHOW CREATE TABLE " . idf_escape($table));
if ($result) {
$create_table = mysql_result($result, 0, 1);
mysql_free_result($result);
preg_match_all('~FOREIGN KEY \\((.+)\\) REFERENCES (?:`(.+)`\\.)?`(.+)` \\((.+)\\)~', $create_table, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
preg_match_all($pattern, $match[1], $source);
preg_match_all($pattern, $match[4], $target);
$return[] = array(idf_unescape($match[2]), idf_unescape($match[3]), array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1]));
}
}
return $return;
}

View file

@ -1,21 +1,30 @@
<?php
$indexes = indexes($_GET["select"]);
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]));
echo '<p><a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . "</a></p>\n";
echo "<form action='' id='form'>\n<fieldset><legend>" . lang('Search') . "</legend>\n";
if (strlen($_GET["server"])) {
echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
$fields = fields($_GET["select"]);
$columns = array();
foreach ($fields as $key => $field) {
if (in_array("select", $field["privileges"])) {
$columns[] = $key;
}
}
echo '<input type="hidden" name="db" value="' . htmlspecialchars($_GET["db"]) . '" />';
echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '" />';
echo "\n";
$where = array();
$columns = array_keys(fields($_GET["select"]));
$operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IS NULL");
$i = 0;
foreach ((array) $_GET["where"] as $val) {
if (!$columns) {
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . mysql_error()) . ".</p>\n";
} else {
echo "<form action='' id='form'>\n<fieldset><legend>" . lang('Search') . "</legend>\n";
if (strlen($_GET["server"])) {
echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
}
echo '<input type="hidden" name="db" value="' . htmlspecialchars($_GET["db"]) . '" />';
echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '" />';
echo "\n";
$where = array();
$operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IS NULL");
$i = 0;
foreach ((array) $_GET["where"] as $val) {
if ($val["col"] && in_array($val["op"], $operators)) {
$where[] = idf_escape($val["col"]) . " $val[op]" . ($val["op"] != "IS NULL" ? " '" . mysql_real_escape_string($val["val"]) . "'" : "");
echo "<div><select name='where[$i][col]'><option></option>" . optionlist($columns, $val["col"], "not_vals") . "</select>";
@ -23,8 +32,8 @@ foreach ((array) $_GET["where"] as $val) {
echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\" /></div>\n";
$i++;
}
}
?>
}
?>
<script type="text/javascript">
function where_change(op) {
op.form[op.name.substr(0, op.name.length - 4) + '[val]'].style.display = (op.value == 'IS NULL' ? 'none' : '');
@ -36,16 +45,16 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
<?php } ?>
</script>
<?php
echo "<div><select name='where[$i][col]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
echo "<select name='where[$i][op]' onchange=\"where_change(this);\">" . optionlist($operators, array(), "not_vals") . "</select>";
echo "<input name='where[$i][val]' /></div>\n"; //! JavaScript for adding next
//! fulltext search
echo "</fieldset>\n";
echo "<div><select name='where[$i][col]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
echo "<select name='where[$i][op]' onchange=\"where_change(this);\">" . optionlist($operators, array(), "not_vals") . "</select>";
echo "<input name='where[$i][val]' /></div>\n"; //! JavaScript for adding next
//! fulltext search
echo "</fieldset>\n";
echo "<fieldset><legend>" . lang('Sort') . "</legend>\n";
$order = array();
$i = 0;
foreach ((array) $_GET["order"] as $key => $val) {
echo "<fieldset><legend>" . lang('Sort') . "</legend>\n";
$order = array();
$i = 0;
foreach ((array) $_GET["order"] as $key => $val) {
if (in_array($val, $columns, true)) {
$desc = in_array($key, (array) $_GET["desc"]);
$order[] = idf_escape($val) . ($desc ? " DESC" : "");
@ -53,25 +62,26 @@ foreach ((array) $_GET["order"] as $key => $val) {
echo "<input type='checkbox' name='desc[]' value='$i' id='desc-$i'" . ($desc ? " checked='checked'" : "") . " /><label for='desc-$i'>" . lang('DESC') . "</label></div>\n";
$i++;
}
}
echo "<div><select name='order[$i]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
echo "<input type='checkbox' name='desc[$i]' value='1' id='desc-$i' /><label for='desc-$i'>" . lang('DESC') . "</label></div>\n";
echo "</fieldset>\n";
}
echo "<div><select name='order[$i]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
echo "<input type='checkbox' name='desc[$i]' value='1' id='desc-$i' /><label for='desc-$i'>" . lang('DESC') . "</label></div>\n";
echo "</fieldset>\n";
echo "<fieldset><legend>" . lang('Limit') . "</legend>\n";
$limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
echo '<div><input name="limit" size="3" value="' . htmlspecialchars($limit) . '" /></div>';
echo "</fieldset>\n";
echo "<fieldset><legend>" . lang('Limit') . "</legend>\n";
$limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
echo '<div><input name="limit" size="3" value="' . htmlspecialchars($limit) . '" /></div>';
echo "</fieldset>\n";
echo "<fieldset><legend>" . lang('Action') . "</legend><div><input type='submit' value='" . lang('Select') . "' /></div></fieldset>\n";
echo "</form>\n";
echo "<div style='clear: left; margin-bottom: 1em;'></div>\n";
echo "<fieldset><legend>" . lang('Action') . "</legend><div><input type='submit' value='" . lang('Select') . "' /></div></fieldset>\n";
echo "</form>\n";
echo "<div style='clear: left; margin-bottom: 1em;'></div>\n";
$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . " OFFSET " . ($limit * $_GET["page"]) : ""));
$found_rows = mysql_result(mysql_query(" SELECT FOUND_ROWS()"), 0); // space for mysql.trace_mode
if (!mysql_num_rows($result)) {
$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS " . implode(", ", array_map('idf_escape', $columns)) . " FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . " OFFSET " . ($limit * $_GET["page"]) : ""));
if (!mysql_num_rows($result)) {
echo "<p class='message'>" . lang('No rows.') . "</p>\n";
} else {
} else {
$found_rows = mysql_result(mysql_query(" SELECT FOUND_ROWS()"), 0); // space for mysql.trace_mode
$indexes = indexes($_GET["select"]);
$foreign_keys = array();
foreach (foreign_keys($_GET["select"]) as $foreign_key) {
foreach ($foreign_key[2] as $val) {
@ -131,5 +141,6 @@ if (!mysql_num_rows($result)) {
}
echo "</p>\n";
}
}
mysql_free_result($result);
}
mysql_free_result($result);

View file

@ -2,34 +2,38 @@
page_header(lang('Table') . ": " . htmlspecialchars($_GET["table"]));
$result = mysql_query("SHOW COLUMNS FROM " . idf_escape($_GET["table"]));
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
while ($row = mysql_fetch_assoc($result)) {
if (!$result) {
echo "<p class='error'>" . lang('Unable to show the table definition') . ": " . mysql_error() . ".</p>\n";
} else {
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr><th>" . htmlspecialchars($row["Field"]) . "</th><td>$row[Type]" . ($row["Null"] == "NO" ? "" : " <i>NULL</i>") . "</td></tr>\n";
}
echo "</table>\n";
mysql_free_result($result);
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=' . urlencode($_GET["table"]) . '">' . lang('Alter table') . "</a></p>\n";
}
echo "</table>\n";
mysql_free_result($result);
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=' . urlencode($_GET["table"]) . '">' . lang('Alter table') . "</a></p>\n";
echo "<h3>" . lang('Indexes') . "</h3>\n";
$indexes = indexes($_GET["table"]);
if ($indexes) {
echo "<h3>" . lang('Indexes') . "</h3>\n";
$indexes = indexes($_GET["table"]);
if ($indexes) {
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
foreach ($indexes as $index) {
ksort($index["columns"]);
echo "<tr><td>$index[type]</td><td><i>" . implode("</i>, <i>", $index["columns"]) . "</i></td></tr>\n";
}
echo "</table>\n";
}
echo '<p><a href="' . htmlspecialchars($SELF) . 'indexes=' . urlencode($_GET["table"]) . '">' . lang('Alter indexes') . "</a></p>\n";
}
echo '<p><a href="' . htmlspecialchars($SELF) . 'indexes=' . urlencode($_GET["table"]) . '">' . lang('Alter indexes') . "</a></p>\n";
$foreign_keys = foreign_keys($_GET["table"]);
if ($foreign_keys) {
$foreign_keys = foreign_keys($_GET["table"]);
if ($foreign_keys) {
echo "<h3>" . lang('Foreign keys') . "</h3>\n";
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
foreach ($foreign_keys as $foreign_key) {
echo "<tr><td><em>" . implode("</em>, <em>", $foreign_key[2]) . "</em></td><td>" . (strlen($foreign_key[0]) && $foreign_key[0] !== $_GET["db"] ? "<strong>" . htmlspecialchars($foreign_key[0]) . "</strong>." : "") . htmlspecialchars($foreign_key[1]) . "(<em>" . implode("</em>, <em>", $foreign_key[3]) . "</em>)</td></tr>\n";
}
echo "</table>\n";
}
}
if (mysql_get_server_info() >= 5) {