quote($_POST["collation"]) : ""))) { $failed = true; } $last = $db; } } if (query_redirect(queries(), ME . "db=" . urlencode($last), lang('Database has been created.'), !strlen(DB), false, $failed)) { $result = $connection->query("SHOW TABLES"); while ($row = $result->fetch_row()) { if (!queries("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) { break; } } if (!$row) { queries("DROP DATABASE " . idf_escape(DB)); } queries_redirect(preg_replace('~db=[^&]*&~', '', ME) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'), !$row); } } else { // alter database if (!$_POST["collation"]) { redirect(substr(ME, 0, -1)); } query_redirect("ALTER DATABASE " . idf_escape($_POST["name"]) . " COLLATE " . $connection->quote($_POST["collation"]), substr(ME, 0, -1), lang('Database has been altered.')); } } page_header(strlen(DB) ? lang('Alter database') : lang('Create database'), $error, array(), DB); $collations = collations(); $name = DB; $collate = array(); if ($_POST) { $name = $_POST["name"]; $collate = $_POST["collation"]; } elseif (!strlen(DB)) { // propose database name with limited privileges $result = $connection->query("SHOW GRANTS"); while ($row = $result->fetch_row()) { if (preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~', $row[0], $match) && $match[1]) { $name = stripcslashes(idf_unescape($match[2])); 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]; } } ?>