From 1ecafa5e23e52333fbbdc62833a818555134d0a0 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 17 Apr 2004 00:52:04 +0000 Subject: [PATCH] Added ability to choose the collation for new databases. --- ChangeLog | 4 ++++ db_create.php | 8 +++++-- libraries/mysql_charsets.lib.php | 39 ++++++++++++++++++++++++++++++-- main.php | 8 +------ 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index edb011fe5..ccede2d38 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ phpMyAdmin - Changelog $Id$ $Source$ +2004-04-17 Alexander M. Turek + * db_create.php, main.php, libraries/mysql_charsets.lib.php: + Added ability to choose the collation for new databases. + 2004-04-16 Marc Delisle * lang/french update diff --git a/db_create.php b/db_create.php index 3af8da492..914c111b3 100644 --- a/db_create.php +++ b/db_create.php @@ -24,8 +24,12 @@ $err_url = 'main.php?' . PMA_generate_common_url(); * Builds and executes the db creation sql query */ $sql_query = 'CREATE DATABASE ' . PMA_backquote($db); -if (isset($db_charset) && isset($mysql_charsets) && in_array($db_charset, $mysql_charsets)) { - $sql_query .= ' DEFAULT CHARACTER SET ' . $db_charset; +if (!empty($db_collation) && PMA_MYSQL_INT_VERSION >= 40101) { + list($db_charset) = explode('_', $db_collation); + if (in_array($db_charset, $mysql_charsets) && in_array($db_collation, $mysql_collations[$db_charset])) { + $sql_query .= ' DEFAULT CHARACTER SET ' . $db_charset . ' COLLATE ' . $db_collation; + } + unset($db_charset, $db_collation); } $sql_query .= ';'; diff --git a/libraries/mysql_charsets.lib.php b/libraries/mysql_charsets.lib.php index ee87659a8..c30e2738e 100644 --- a/libraries/mysql_charsets.lib.php +++ b/libraries/mysql_charsets.lib.php @@ -4,7 +4,7 @@ if (PMA_MYSQL_INT_VERSION >= 40100){ - $res = PMA_DBI_query('SHOW CHARACTER SET;', NULL, PMA_DBI_QUERY_STORE); + $res = PMA_DBI_query('SHOW CHARACTER SET;'); $mysql_charsets = array(); while ($row = PMA_DBI_fetch_assoc($res)) { @@ -15,7 +15,7 @@ if (PMA_MYSQL_INT_VERSION >= 40100){ @PMA_DBI_free_result($res); unset($res, $row); - $res = PMA_DBI_query('SHOW COLLATION;', NULL, PMA_DBI_QUERY_STORE); + $res = PMA_DBI_query('SHOW COLLATION;'); $mysql_charsets_count = count($mysql_charsets); sort($mysql_charsets, SORT_STRING); @@ -252,6 +252,41 @@ if (PMA_MYSQL_INT_VERSION >= 40100){ return ''; } + define('PMA_CSDROPDOWN_COLLATION', 0); + define('PMA_CSDROPDOWN_CHARSET', 1); + + function PMA_printCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION, $name = NULL, $id = NULL, $label = TRUE, $indent = 0) { + global $mysql_charsets, $mysql_charsets_descriptions, $mysql_collations; + + if (empty($name)) { + if ($type == PMA_CSDROPDOWN_COLLATION) { + $name = 'collation'; + } else { + $name = 'character_set'; + } + } + for ($i = 1; $i <= $indent; $i++) $spacer .= ' '; + + echo $spacer . '' . "\n"; + } + } ?> diff --git a/main.php b/main.php index 2ea590697..432527066 100644 --- a/main.php +++ b/main.php @@ -305,13 +305,7 @@ if ($server > 0) { . ' ' . "\n"; if (PMA_MYSQL_INT_VERSION >= 40101) { require_once('./libraries/mysql_charsets.lib.php'); - echo ' ' . "\n"; + PMA_printCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', NULL, TRUE, 5); } echo ' ' . "\n" . ' ' . "\n"