3 // vim: expandtab sw=4 ts=4 sts=4:
5 if (PMA_MYSQL_INT_VERSION
>= 40100){
7 $res = PMA_DBI_query('SHOW CHARACTER SET;');
9 $mysql_charsets = array();
10 while ($row = PMA_DBI_fetch_assoc($res)) {
11 $mysql_charsets[] = $row['Charset'];
13 //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
14 $mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
16 @PMA_DBI_free_result
( $res );
18 $mysql_charsets_count = count($mysql_charsets);
19 sort($mysql_charsets, SORT_STRING
);
21 $mysql_collations = array_flip($mysql_charsets);
22 $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
24 $res = PMA_DBI_query('SHOW COLLATION;');
25 while ($row = PMA_DBI_fetch_assoc($res)) {
26 if (!is_array($mysql_collations[$row['Charset']])) {
27 $mysql_collations[$row['Charset']] = array($row['Collation']);
29 $mysql_collations[$row['Charset']][] = $row['Collation'];
31 $mysql_collations_flat[] = $row['Collation'];
32 if ((isset($row['D']) && $row['D'] == 'Y') ||
(isset($row['Default']) && $row['Default'] == 'Yes')) {
33 $mysql_default_collations[$row['Charset']] = $row['Collation'];
35 //$mysql_collations_available[$row['Collation']] = !isset($row['Compiled']) || $row['Compiled'] == 'Yes';
36 $mysql_collations_available[$row['Collation']] = TRUE;
37 $mysql_charsets_available[$row['Charset']] = !empty($mysql_charsets_available[$row['Charset']]) ||
!empty($mysql_collations_available[$row['Collation']]);
39 @PMA_DBI_free_result
( $res );
42 $mysql_collations_count = count($mysql_collations_flat);
43 sort($mysql_collations_flat, SORT_STRING
);
44 foreach ($mysql_collations AS $key => $value) {
45 sort($mysql_collations[$key], SORT_STRING
);
46 reset($mysql_collations[$key]);
48 unset( $key, $value );
50 define('PMA_CSDROPDOWN_COLLATION', 0);
51 define('PMA_CSDROPDOWN_CHARSET', 1);
53 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION
, $name = null, $id = null, $default = null, $label = TRUE, $indent = 0, $submitOnChange = FALSE, $displayUnavailable = FALSE) {
54 global $mysql_charsets, $mysql_charsets_descriptions, $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
57 if ($type == PMA_CSDROPDOWN_COLLATION
) {
60 $name = 'character_set';
65 for ($i = 1; $i <= $indent; $i++
) $spacer .= ' ';
67 $return_str = $spacer . '<select xml:lang="en" dir="ltr" name="' . htmlspecialchars($name) . '"' . (empty($id) ?
'' : ' id="' . htmlspecialchars($id) . '"') . ($submitOnChange ?
' onchange="this.form.submit();"' : '') . '>' . "\n";
69 $return_str .= $spacer . ' <option value="">' . ($type == PMA_CSDROPDOWN_COLLATION ?
$GLOBALS['strCollation'] : $GLOBALS['strCharset']) . '</option>' . "\n";
71 $return_str .= $spacer . ' <option value=""></option>' . "\n";
72 foreach ($mysql_charsets as $current_charset) {
73 if (!$mysql_charsets_available[$current_charset]) {
76 $current_cs_descr = empty($mysql_charsets_descriptions[$current_charset]) ?
$current_charset : $mysql_charsets_descriptions[$current_charset];
77 if ($type == PMA_CSDROPDOWN_COLLATION
) {
78 $return_str .= $spacer . ' <optgroup label="' . $current_charset . '" title="' . $current_cs_descr . '">' . "\n";
79 foreach ($mysql_collations[$current_charset] as $current_collation) {
80 if (!$mysql_collations_available[$current_collation]) {
83 $return_str .= $spacer . ' <option value="' . $current_collation . '" title="' . PMA_getCollationDescr($current_collation) . '"' . ($default == $current_collation ?
' selected="selected"' : '') . '>' . $current_collation . '</option>' . "\n";
85 $return_str .= $spacer . ' </optgroup>' . "\n";
87 $return_str .= $spacer . ' <option value="' . $current_charset . '" title="' . $current_cs_descr . '"' . ($default == $current_charset ?
' selected="selected"' : '') . '>' . $current_charset . '</option>' . "\n";
90 $return_str .= $spacer . '</select>' . "\n";
95 function PMA_generateCharsetQueryPart($collation) {
96 list($charset) = explode('_', $collation);
97 return ' CHARACTER SET ' . $charset . ($charset == $collation ?
'' : ' COLLATE ' . $collation);
101 * returns collation of given db
103 * @uses PMA_MYSQL_INT_VERSION
104 * @uses PMA_DBI_fetch_value()
105 * @uses PMA_DBI_select_db()
106 * @uses PMA_sqlAddSlashes()
107 * @uses $GLOBALS['db']
108 * @param string $db name of db
109 * @return string collation of $db
111 function PMA_getDbCollation( $db ) {
112 if ( PMA_MYSQL_INT_VERSION
>= 50000 && $db == 'information_schema' ) {
113 // We don't have to check the collation of the virtual
114 // information_schema database: We know it!
115 return 'utf8_general_ci';
117 if ( PMA_MYSQL_INT_VERSION
>= 50006 ) {
118 // Since MySQL 5.0.6, we don't have to parse SHOW CREATE DATABASE anymore.
119 return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;');
120 } elseif ( PMA_MYSQL_INT_VERSION
>= 40101 ) {
121 // MySQL 4.1.0 does not support seperate charset settings
123 PMA_DBI_select_db( $db );
124 $return = PMA_DBI_fetch_value( 'SHOW VARIABLES LIKE "collation_database"', 0, 1 );
125 if ( isset( $GLOBALS['db'] ) && $db !== $GLOBALS['db'] ) {
126 PMA_DBI_select_db( $GLOBALS['db'] );
134 function PMA_getDbCollation( $db ) { return PMA_getServerCollation(); }
138 * returns default server collation from show variables
140 * @uses PMA_DBI_fetch_value()
141 * @return string $server_collation
143 function PMA_getServerCollation() {
144 return PMA_DBI_fetch_value(
145 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1 );
149 * returns description for given collation
154 * @uses $GLOBALS['str[Languages|Sorting]']
156 * @param string $collation MySQL collation string
157 * @return string collation description
159 function PMA_getCollationDescr( $collation ) {
160 static $collation_cache;
162 if (!is_array($collation_cache)) {
163 $collation_cache = array();
164 } elseif (isset($collation_cache[$collation])) {
165 return $collation_cache[$collation];
168 if ($collation == 'binary') {
169 return $GLOBALS['strBinary'];
171 $parts = explode('_', $collation);
172 if (count($parts) == 1) {
173 $parts[1] = 'general';
174 } elseif ($parts[1] == 'ci' ||
$parts[1] == 'cs') {
175 $parts[2] = $parts[1];
176 $parts[1] = 'general';
181 $descr = $GLOBALS['strBulgarian'];
184 if ($parts[0] == 'gb2312' ||
$parts[0] == 'gbk') {
185 $descr = $GLOBALS['strSimplifiedChinese'];
186 } elseif ($parts[0] == 'big5') {
187 $descr = $GLOBALS['strTraditionalChinese'];
191 $descr = $GLOBALS['strCaseInsensitive'];
194 $descr = $GLOBALS['strCaseSensitive'];
197 $descr = $GLOBALS['strCroatian'];
200 $descr = $GLOBALS['strCzech'];
203 $descr = $GLOBALS['strDanish'];
206 $descr = $GLOBALS['strEnglish'];
209 $descr = $GLOBALS['strEsperanto'];
212 $descr = $GLOBALS['strEstonian'];
215 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strDictionary'] . ')';
218 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strPhoneBook'] . ')';
221 $descr = $GLOBALS['strHungarian'];
224 $descr = $GLOBALS['strIcelandic'];
227 $descr = $GLOBALS['strJapanese'];
230 $descr = $GLOBALS['strLatvian'];
233 $descr = $GLOBALS['strLithuanian'];
236 $descr = $GLOBALS['strKorean'];
239 $descr = $GLOBALS['strPersian'];
242 $descr = $GLOBALS['strPolish'];
245 $descr = $GLOBALS['strWestEuropean'];
248 $descr = $GLOBALS['strRomanian'];
251 $descr = $GLOBALS['strSlovak'];
254 $descr = $GLOBALS['strSlovenian'];
257 $descr = $GLOBALS['strSpanish'];
260 $descr = $GLOBALS['strTraditionalSpanish'];
263 $descr = $GLOBALS['strSwedish'];
266 $descr = $GLOBALS['strThai'];
269 $descr = $GLOBALS['strTurkish'];
272 $descr = $GLOBALS['strUkrainian'];
275 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
284 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
286 // West European charsets
293 $descr = $GLOBALS['strWestEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
295 // Central European charsets
300 $descr = $GLOBALS['strCentralEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
305 $descr = $GLOBALS['strRussian'];
307 // Simplified Chinese charsets
310 $descr = $GLOBALS['strSimplifiedChinese'];
317 $descr = $GLOBALS['strJapanese'];
322 $descr = $GLOBALS['strBaltic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
327 $descr = $GLOBALS['strArmenian'];
330 $descr = $GLOBALS['strTraditionalChinese'];
333 $descr = $GLOBALS['strCyrillic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
336 $descr = $GLOBALS['strArabic'];
339 $descr = $GLOBALS['strKorean'];
342 $descr = $GLOBALS['strHebrew'];
345 $descr = $GLOBALS['strGeorgian'];
348 $descr = $GLOBALS['strGreek'];
351 $descr = $GLOBALS['strCzechSlovak'];
354 $descr = $GLOBALS['strUkrainian'];
357 $descr = $GLOBALS['strTurkish'];
360 $descr = $GLOBALS['strSwedish'];
363 $descr = $GLOBALS['strThai'];
366 $descr = $GLOBALS['strUnknown'];
369 if (!empty($is_bin)) {
370 $descr .= ', ' . $GLOBALS['strBinary'];
373 default: $descr = $GLOBALS['strUnknown'];
375 if (!empty($parts[2])) {
376 if ($parts[2] == 'ci') {
377 $descr .= ', ' . $GLOBALS['strCaseInsensitive'];
378 } elseif ($parts[2] == 'cs') {
379 $descr .= ', ' . $GLOBALS['strCaseSensitive'];
383 $collation_cache[$collation] = $descr;