[adminer-svn] SF.net SVN: adminer:[1195] trunk
Database management in a single PHP file
Brought to you by:
jakubvrana
From: <jak...@us...> - 2009-10-18 09:29:11
|
Revision: 1195 http://adminer.svn.sourceforge.net/adminer/?rev=1195&view=rev Author: jakubvrana Date: 2009-10-18 09:29:01 +0000 (Sun, 18 Oct 2009) Log Message: ----------- Database list - bulk drop, number of tables Modified Paths: -------------- trunk/adminer/database.inc.php trunk/adminer/db.inc.php trunk/adminer/include/connect.inc.php trunk/adminer/include/mysql.inc.php trunk/todo.txt Modified: trunk/adminer/database.inc.php =================================================================== --- trunk/adminer/database.inc.php 2009-10-17 07:16:02 UTC (rev 1194) +++ trunk/adminer/database.inc.php 2009-10-18 09:29:01 UTC (rev 1195) @@ -1,9 +1,6 @@ <?php if ($_POST && !$error && !isset($_POST["add_x"])) { // add is an image and PHP changes add.x to add_x - if ($_POST["drop"]) { - unset($_SESSION["databases"][$_GET["server"]]); - query_redirect("DROP DATABASE " . idf_escape(DB), substr(preg_replace('~db=[^&]*&~', '', ME), 0, -1), lang('Database has been dropped.')); - } elseif (DB !== $_POST["name"]) { + if (DB !== $_POST["name"]) { // create or rename database unset($_SESSION["databases"][$_GET["server"]]); // clear cache $dbs = explode("\n", str_replace("\r", "", $_POST["name"])); @@ -42,7 +39,7 @@ $collations = collations(); $name = DB; -$collate = array(); +$collate = null; if ($_POST) { $name = $_POST["name"]; $collate = $_POST["collation"]; @@ -55,14 +52,8 @@ break; } } -} elseif (($result = $connection->query("SHOW CREATE DATABASE " . idf_escape(DB)))) { - $create = $connection->result($result, 1); - if (preg_match('~ COLLATE ([^ ]+)~', $create, $match)) { - $collate = $match[1]; - } elseif (preg_match('~ CHARACTER SET ([^ ]+)~', $create, $match)) { - // default collation - $collate = $collations[$match[1]][0]; - } +} else { + $collate = db_collation(DB, $collations); } ?> @@ -76,9 +67,7 @@ <input type="hidden" name="token" value="<?php echo $token; ?>"> <input type="submit" value="<?php echo lang('Save'); ?>"> <?php -if (strlen(DB)) { - echo "<input type='submit' name='drop' value='" . lang('Drop') . "'$confirm>\n"; -} elseif (!$_POST["add_x"]) { +if (!$_POST["add_x"]) { echo "<input type='image' name='add' src='../adminer/static/plus.gif' alt='+' title='" . lang('Add next') . "'>\n"; } ?> Modified: trunk/adminer/db.inc.php =================================================================== --- trunk/adminer/db.inc.php 2009-10-17 07:16:02 UTC (rev 1194) +++ trunk/adminer/db.inc.php 2009-10-18 09:29:01 UTC (rev 1195) @@ -39,7 +39,7 @@ page_header(lang('Database') . ": " . h(DB), $error, false); echo '<p><a href="' . h(ME) . 'database=">' . lang('Alter database') . "</a>\n"; -echo '<p><a href="' . h(ME) . 'schema=">' . lang('Database schema') . "</a>\n"; +echo '<a href="' . h(ME) . 'schema=">' . lang('Database schema') . "</a>\n"; echo "<h3>" . lang('Tables and views') . "</h3>\n"; $table_status = table_status(); Modified: trunk/adminer/include/connect.inc.php =================================================================== --- trunk/adminer/include/connect.inc.php 2009-10-17 07:16:02 UTC (rev 1194) +++ trunk/adminer/include/connect.inc.php 2009-10-18 09:29:01 UTC (rev 1195) @@ -1,20 +1,50 @@ <?php function connect_error() { - global $connection, $VERSION; + global $connection, $VERSION, $token, $error; if (strlen(DB)) { page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), false); } else { + if ($_POST["db"] && !$error) { + unset($_SESSION["databases"][$_GET["server"]]); + foreach ($_POST["db"] as $db) { + if (!queries("DROP DATABASE " . idf_escape($db))) { + break; + } + } + queries_redirect(substr(ME, 0, -1), lang('Database has been dropped.'), !$connection->error); + } + page_header(lang('Select database'), "", null); + echo "<p>"; foreach (array( 'database' => lang('Create new database'), 'privileges' => lang('Privileges'), 'processlist' => lang('Process list'), 'variables' => lang('Variables'), ) as $key => $val) { - echo "<p><a href='" . h(ME) . "$key='>$val</a>\n"; + echo "<a href='" . h(ME) . "$key='>$val</a>\n"; } echo "<p>" . lang('MySQL version: %s through PHP extension %s', "<b" . ($connection->server_info < 4.1 ? " class='binary'" : "") . ">$connection->server_info</b>", "<b>$connection->extension</b>") . "\n"; echo "<p>" . lang('Logged as: %s', "<b>" . h($connection->result($connection->query("SELECT USER()"))) . "</b>") . "\n"; + $databases = get_databases(); + if ($databases) { + $collations = collations(); + echo "<form action='' method='post'>\n"; + echo "<table cellspacing='0' onclick='table_click(event);'>\n"; + echo "<thead><tr><td><input type='hidden' name='token' value='$token'> <th>" . lang('Database') . "<td>" . lang('Collation') . "<td>" . lang('Tables') . "</thead>\n"; + foreach ($databases as $db) { + $root = h(ME) . "db=" . urlencode($db); + echo "<tr><td>" . checkbox("db[]", $db, false); + echo "<th><a href='$root'>" . h($db) . "</a>"; + echo "<td><a href='$root&database='>" . nbsp(db_collation($db, $collations)) . "</a>"; + $result = $connection->query("SHOW TABLES FROM " . idf_escape($db)); + echo "<td><a href='$root&schema='>$result->num_rows</a>"; + echo "\n"; + } + echo "</table>\n"; + echo "<p><input type='submit' name='drop' value='" . lang('Drop') . "' onclick=\"return confirm('" . lang('Are you sure?') . " (' + form_checked(this, /db/) + ')');\">\n"; + echo "</form>\n"; + } } page_footer("db"); } Modified: trunk/adminer/include/mysql.inc.php =================================================================== --- trunk/adminer/include/mysql.inc.php 2009-10-17 07:16:02 UTC (rev 1194) +++ trunk/adminer/include/mysql.inc.php 2009-10-18 09:29:01 UTC (rev 1195) @@ -177,6 +177,30 @@ return $return; } +/** Get database collation +* @param string +* @param array result of collations() +* @return +*/ +function db_collation($db, $collations) { + global $connection; + $return = null; + $result = $connection->query("SHOW CREATE DATABASE " . idf_escape($db)); + if ($result) { + $create = $connection->result($result, 1); + if (preg_match('~ COLLATE ([^ ]+)~', $create, $match)) { + $return = $match[1]; + } elseif (preg_match('~ CHARACTER SET ([^ ]+)~', $create, $match)) { + // default collation + $return = $collations[$match[1]][0]; + } + } + return $return; +} + +/**Get supported engines +* @return array +*/ function engines() { global $connection; $return = array(); Modified: trunk/todo.txt =================================================================== --- trunk/todo.txt 2009-10-17 07:16:02 UTC (rev 1194) +++ trunk/todo.txt 2009-10-18 09:29:01 UTC (rev 1195) @@ -1,4 +1,3 @@ -Bulk database drop Add whisperer to fields with foreign key Highlight found fields MySQL 5 BIT data type This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |