1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-13 10:04:07 +02:00

Detect collation from charset

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@256 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana
2007-07-25 19:54:56 +00:00
parent 9b622fe6fc
commit 964520252c
2 changed files with 11 additions and 3 deletions

View 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 } ?>

View 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;