]> git.joonet.de Git - adminer.git/commitdiff
Detect collation from charset
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 25 Jul 2007 19:54:56 +0000 (19:54 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 25 Jul 2007 19:54:56 +0000 (19:54 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@256 7c3ca157-0c34-0410-bff1-cbf682f78f5c

database.inc.php
functions.inc.php

index ea52f10eed89b994c45ebd2bdbc1520567995b04..b13b203249c29515cad2ccfaeeb3b4a25bb05365 100644 (file)
@@ -30,6 +30,7 @@ if ($_POST && !$error) {
 }
 
 page_header(strlen($_GET["db"]) ? lang('Alter database') . ": " . htmlspecialchars($_GET["db"]) : lang('Create database'));
+$collations = collations();
 
 if ($_POST) {
        echo "<p class='error'>" . lang('Unable to operate database') . ": " . htmlspecialchars($error) . "</p>\n";
@@ -39,8 +40,11 @@ if ($_POST) {
        $name = $_GET["db"];
        $collate = array();
        if (strlen($_GET["db"]) && ($result = $mysql->query("SHOW CREATE DATABASE " . idf_escape($_GET["db"])))) {
-               if (preg_match('~ COLLATE ([^ ]+)~', $mysql->result($result, 1), $match)) {
+               $create = $mysql->result($result, 1);
+               if (preg_match('~ COLLATE ([^ ]+)~', $create, $match)) {
                        $collate = $match[1];
+               } elseif (preg_match('~ CHARACTER SET ([^ ]+)~', $create, $match)) {
+                       $collate = $collations[$match[1]][0];
                }
                $result->free();
        }
@@ -50,7 +54,7 @@ if ($_POST) {
 <form action="" method="post">
 <p>
 <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); ?></select>
+<select name="collation"><option value="">(<?php echo lang('collation'); ?>)</option><?php echo optionlist($collations, $collate); ?></select>
 <input type="hidden" name="token" value="<?php echo $token; ?>" />
 <input type="submit" value="<?php echo lang('Save'); ?>" />
 <?php if (strlen($_GET["db"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" /><?php } ?>
index 264531d03e1b87d9eee3635c5967b427977bd3d5..86a36c0ece6654034a8da42227004b490e6f78e3 100644 (file)
@@ -159,7 +159,11 @@ function collations() {
        $return = array();
        $result = $mysql->query("SHOW COLLATION");
        while ($row = $result->fetch_assoc()) {
-               $return[$row["Charset"]][] = $row["Collation"];
+               if ($row["Default"] && $return[$row["Charset"]]) {
+                       array_unshift($return[$row["Charset"]], $row["Collation"]);
+               } else {
+                       $return[$row["Charset"]][] = $row["Collation"];
+               }
        }
        $result->free();
        return $return;