]> git.joonet.de Git - adminer.git/commitdiff
Database operations
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Mon, 2 Jul 2007 20:21:30 +0000 (20:21 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Mon, 2 Jul 2007 20:21:30 +0000 (20:21 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@14 7c3ca157-0c34-0410-bff1-cbf682f78f5c

connect.inc.php
database.inc.php [new file with mode: 0644]
design.inc.php
index.php

index bc6980847e5b7a40d0fe5904e5d6ecf1cd41ae35..c255449f6f73e8e78e95a0b62f878012c26a3f87 100644 (file)
@@ -1,8 +1,10 @@
 <?php
-if (!(strlen($_GET["db"]) ? mysql_select_db($_GET["db"]) : isset($_GET["sql"]) || isset($_GET["dump"]))) {
-       page_header((isset($_GET["db"]) ? lang('Invalid database') : lang('Select database')), "db");
+if (!(strlen($_GET["db"]) ? mysql_select_db($_GET["db"]) : isset($_GET["sql"]) || isset($_GET["dump"]) || isset($_GET["database"]))) {
+       page_header((strlen($_GET["db"]) ? lang('Invalid database') : lang('Select database')), "db");
        if (strlen($_GET["db"])) {
                echo "<p class='error'>" . lang('Invalid database.') . "</p>\n";
+       } else {
+               echo '<a href="' . htmlspecialchars($SELF) . 'database=">' . lang('Create new database') . '</a>';
        }
        page_footer();
        exit;
diff --git a/database.inc.php b/database.inc.php
new file mode 100644 (file)
index 0000000..0129b7e
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+if ($_POST) {
+       if ($_POST["drop"]) {
+               if (mysql_query("DROP DATABASE " . idf_escape($_GET["db"]))) {
+                       $_SESSION["message"] = lang('Database has been dropped.');
+                       $location = substr(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . (SID ? SID . "&" : ""), 0, -1);
+                       header("Location: " . (strlen($location) ? $location : "."));
+                       exit;
+               }
+       } elseif ($_GET["db"] !== $_POST["name"]) {
+               if (mysql_query("CREATE DATABASE " . idf_escape($_POST["name"]) . ($_POST["collation"] ? " COLLATE '" . mysql_real_escape_string($_POST["collation"]) . "'" : ""))) {
+                       if (!strlen($_GET["db"])) {
+                               $_SESSION["message"] = lang('Database has been created.');
+                               header("Location: " . substr(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]) . "&" . (SID ? SID . "&" : ""), 0, -1));
+                               exit;
+                       }
+                       $result = mysql_query("SHOW TABLES");
+                       while ($row = mysql_fetch_row($result)) {
+                               if (!mysql_query("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) {
+                                       break;
+                               }
+                       }
+                       mysql_free_result($result);
+                       if (!$row) {
+                               mysql_query("DROP DATABASE " . idf_escape($_GET["db"]));
+                               $_SESSION["message"] = lang('Database has been renamed.');
+                               header("Location: " . substr(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]) . "&" . (SID ? SID . "&" : ""), 0, -1));
+                               exit;
+                       }
+               }
+       } elseif (!$_POST["collation"] || mysql_query("ALTER DATABASE " . idf_escape($_POST["name"]) . " COLLATE '" . mysql_real_escape_string($_POST["collation"]) . "'")) {
+               $_SESSION["message"] = ($_POST["collation"] ? lang('Database has been altered.') : '');
+               header("Location: " . substr($SELF . (SID ? SID . "&" : ""), 0, -1));
+               exit;
+       }
+       $eror = mysql_error();
+}
+
+page_header(strlen($_GET["db"]) ? lang('Alter database') . ": " . htmlspecialchars($_GET["db"]) : lang('Create database'));
+echo "<h2>" . (strlen($_GET["db"]) ? lang('Alter database') . ": " . htmlspecialchars($_GET["db"]) : lang('Create database')) . "</h2>\n";
+
+if ($_POST) {
+       echo "<p class='error'>" . lang('Unable to operate database') . ": " . htmlspecialchars($error) . "</p>\n";
+       $name = $_POST["name"];
+       $collate = $_POST["collate"];
+} else {
+       $name = $_GET["db"];
+       $collate = array(); //! take from SHOW CREATE DATABASE
+}
+?>
+<form action="" method="post"><div>
+<input name="name" value="<?php echo htmlspecialchars($name); ?>" maxlength="64" />
+<select name="collation"><option value="">(<?php echo lang('collation'); ?>)</option><?php echo optionlist(collations(), $collate, "not_vals"); ?></select>
+<input type="submit" value="<?php echo lang('Save'); ?>" />
+<?php if (strlen($_GET["db"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" /><?php } ?>
+</div></form>
index c1ce957d0e408579d2dca3b1b3b271c53166210f..23c8fd2e012beae52521c074d49317b29ef9d226 100644 (file)
@@ -37,7 +37,6 @@ H2 { font-size: 150%; margin-top: 0; }
 <form action="" method="get">
 <p><select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)</option>
 <?php
-               //! create database
                $result = mysql_query("SHOW DATABASES");
                while ($row = mysql_fetch_row($result)) {
                        echo "<option" . ($row[0] == $_GET["db"] ? " selected='selected'" : "") . ">" . htmlspecialchars($row[0]) . "</option>\n";
@@ -48,7 +47,7 @@ H2 { font-size: 150%; margin-top: 0; }
 <noscript><p><input type="submit" value="<?php echo lang('Use'); ?>" /></p></noscript>
 </form>
 <?php
-               if ($missing != "db") {
+               if ($missing != "db" && strlen($_GET["db"])) {
                        $result = mysql_query("SHOW TABLES");
                        if (!mysql_num_rows($result)) {
                                echo "<p class='message'>" . lang('No tables.') . "</p>\n";
index 7e29592eb21ccd193b9a7bdc8d79a9781c9c3aaf..58e200856282c75df451aa7ce188c431ade0e858 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,7 +1,7 @@
 <?php
 session_start();
 error_reporting(E_ALL & ~E_NOTICE);
-$SELF = preg_replace('~^[^?]*/([^?]*).*~', '\\1?', $_SERVER["REQUEST_URI"]) . (strlen($_GET["server"]) ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (isset($_GET["db"]) ? 'db=' . urlencode($_GET["db"]) . '&' : '');
+$SELF = preg_replace('~^[^?]*/([^?]*).*~', '\\1?', $_SERVER["REQUEST_URI"]) . (strlen($_GET["server"]) ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (strlen($_GET["db"]) ? 'db=' . urlencode($_GET["db"]) . '&' : '');
 include "./functions.inc.php";
 include "./design.inc.php";
 include "./auth.inc.php";
@@ -21,9 +21,11 @@ if (isset($_GET["sql"])) {
        include "./dump.inc.php";
 } elseif (isset($_GET["view"])) {
        include "./view.inc.php";
+} elseif (isset($_GET["database"])) {
+       include "./database.inc.php";
 } else {
        page_header(htmlspecialchars($_GET["db"]));
-       //! alter and drop database
+       echo '<p><a href="' . htmlspecialchars($SELF) . 'database=">' . lang('Alter database') . "</a></p>\n";
        $result = mysql_query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = '" . mysql_real_escape_string($_GET["db"]) . "'");
        if (mysql_num_rows($result)) {
                echo "<h2>" . lang('Routines') . "</h2>\n";