2 /* vim: set expandtab sw=4 ts=4 sts=4: */
7 if (! defined('PHPMYADMIN')) {
14 if (! PMA_cacheExists('mysql_charsets', true)) {
16 ?
'SELECT * FROM data_dictionary.CHARACTER_SETS'
17 : 'SELECT * FROM information_schema.CHARACTER_SETS';
18 $res = PMA_DBI_query($sql);
20 $mysql_charsets = array();
21 while ($row = PMA_DBI_fetch_assoc($res)) {
22 $mysql_charsets[] = $row['CHARACTER_SET_NAME'];
24 //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
25 $mysql_charsets_descriptions[$row['CHARACTER_SET_NAME']] = $row['DESCRIPTION'];
27 PMA_DBI_free_result($res);
29 sort($mysql_charsets, SORT_STRING
);
31 $mysql_collations = array_flip($mysql_charsets);
32 $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
35 ?
'SELECT * FROM data_dictionary.COLLATIONS'
36 : 'SELECT * FROM information_schema.COLLATIONS';
37 $res = PMA_DBI_query($sql);
38 while ($row = PMA_DBI_fetch_assoc($res)) {
39 if (! is_array($mysql_collations[$row['CHARACTER_SET_NAME']])) {
40 $mysql_collations[$row['CHARACTER_SET_NAME']] = array($row['COLLATION_NAME']);
42 $mysql_collations[$row['CHARACTER_SET_NAME']][] = $row['COLLATION_NAME'];
44 $mysql_collations_flat[] = $row['COLLATION_NAME'];
45 if ($row['IS_DEFAULT'] == 'Yes' ||
$row['IS_DEFAULT'] == '1') {
46 $mysql_default_collations[$row['CHARACTER_SET_NAME']] = $row['COLLATION_NAME'];
48 //$mysql_collations_available[$row['Collation']] = ! isset($row['Compiled']) || $row['Compiled'] == 'Yes';
49 $mysql_collations_available[$row['COLLATION_NAME']] = true;
50 $mysql_charsets_available[$row['CHARACTER_SET_NAME']] =
51 !empty($mysql_charsets_available[$row['CHARACTER_SET_NAME']])
52 ||
!empty($mysql_collations_available[$row['COLLATION_NAME']]);
54 PMA_DBI_free_result($res);
57 if (PMA_DRIZZLE
&& isset($mysql_collations['utf8_general_ci']) && isset($mysql_collations['utf8'])) {
58 $mysql_collations['utf8'] = $mysql_collations['utf8_general_ci'];
59 $mysql_default_collations['utf8'] = $mysql_default_collations['utf8_general_ci'];
60 $mysql_charsets_available['utf8'] = $mysql_charsets_available['utf8_general_ci'];
61 unset($mysql_collations['utf8_general_ci'], $mysql_default_collations['utf8_general_ci'],
62 $mysql_charsets_available['utf8_general_ci']);
65 sort($mysql_collations_flat, SORT_STRING
);
66 foreach ($mysql_collations AS $key => $value) {
67 sort($mysql_collations[$key], SORT_STRING
);
68 reset($mysql_collations[$key]);
72 PMA_cacheSet('mysql_charsets', $GLOBALS['mysql_charsets'], true);
73 PMA_cacheSet('mysql_charsets_descriptions', $GLOBALS['mysql_charsets_descriptions'], true);
74 PMA_cacheSet('mysql_charsets_available', $GLOBALS['mysql_charsets_available'], true);
75 PMA_cacheSet('mysql_collations', $GLOBALS['mysql_collations'], true);
76 PMA_cacheSet('mysql_default_collations', $GLOBALS['mysql_default_collations'], true);
77 PMA_cacheSet('mysql_collations_flat', $GLOBALS['mysql_collations_flat'], true);
78 PMA_cacheSet('mysql_collations_available', $GLOBALS['mysql_collations_available'], true);
80 $GLOBALS['mysql_charsets'] = PMA_cacheGet('mysql_charsets', true);
81 $GLOBALS['mysql_charsets_descriptions'] = PMA_cacheGet('mysql_charsets_descriptions', true);
82 $GLOBALS['mysql_charsets_available'] = PMA_cacheGet('mysql_charsets_available', true);
83 $GLOBALS['mysql_collations'] = PMA_cacheGet('mysql_collations', true);
84 $GLOBALS['mysql_default_collations'] = PMA_cacheGet('mysql_default_collations', true);
85 $GLOBALS['mysql_collations_flat'] = PMA_cacheGet('mysql_collations_flat', true);
86 $GLOBALS['mysql_collations_available'] = PMA_cacheGet('mysql_collations_available', true);
89 define('PMA_CSDROPDOWN_COLLATION', 0);
90 define('PMA_CSDROPDOWN_CHARSET', 1);
92 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION
,
93 $name = null, $id = null, $default = null, $label = true, $indent = 0,
94 $submitOnChange = false, $displayUnavailable = false)
96 global $mysql_charsets, $mysql_charsets_descriptions,
97 $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
100 if ($type == PMA_CSDROPDOWN_COLLATION
) {
103 $name = 'character_set';
107 $return_str = '<select xml:lang="en" dir="ltr" name="'
108 . htmlspecialchars($name) . '"'
109 . (empty($id) ?
'' : ' id="' . htmlspecialchars($id) . '"')
110 . ($submitOnChange ?
' onchange="this.form.submit();"' : '') . '>' . "\n";
112 $return_str .= '<option value="">'
113 . ($type == PMA_CSDROPDOWN_COLLATION ?
__('Collation') : __('Charset'))
114 . '</option>' . "\n";
116 $return_str .= '<option value=""></option>' . "\n";
117 foreach ($mysql_charsets as $current_charset) {
118 if (!$mysql_charsets_available[$current_charset]) {
122 empty($mysql_charsets_descriptions[$current_charset])
124 : $mysql_charsets_descriptions[$current_charset];
126 if ($type == PMA_CSDROPDOWN_COLLATION
) {
127 $return_str .= '<optgroup label="' . $current_charset
128 . '" title="' . $current_cs_descr . '">' . "\n";
129 foreach ($mysql_collations[$current_charset] as $current_collation) {
130 if (!$mysql_collations_available[$current_collation]) {
133 $return_str .= '<option value="' . $current_collation
134 . '" title="' . PMA_getCollationDescr($current_collation) . '"'
135 . ($default == $current_collation ?
' selected="selected"' : '') . '>'
136 . $current_collation . '</option>' . "\n";
138 $return_str .= '</optgroup>' . "\n";
140 $return_str .= '<option value="' . $current_charset
141 . '" title="' . $current_cs_descr . '"'
142 . ($default == $current_charset ?
' selected="selected"' : '') . '>'
143 . $current_charset . '</option>' . "\n";
146 $return_str .= '</select>' . "\n";
151 function PMA_generateCharsetQueryPart($collation) {
153 list($charset) = explode('_', $collation);
154 return ' CHARACTER SET ' . $charset . ($charset == $collation ?
'' : ' COLLATE ' . $collation);
156 return ' COLLATE ' . $collation;
161 * returns collation of given db
163 * @param string $db name of db
164 * @return string collation of $db
166 function PMA_getDbCollation($db) {
167 if (strtolower($db) == 'information_schema' ||
(PMA_DRIZZLE
&& strtolower($db) == 'data_dictionary')) {
168 // We don't have to check the collation of the virtual
169 // information_schema database: We know it!
170 return 'utf8_general_ci';
173 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
174 // this is slow with thousands of databases
176 ?
'SELECT DEFAULT_COLLATION_NAME FROM data_dictionary.SCHEMAS WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1'
177 : 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1';
178 return PMA_DBI_fetch_value($sql);
180 PMA_DBI_select_db($db);
181 $return = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'collation_database\'', 0, 1);
182 if ($db !== $GLOBALS['db']) {
183 PMA_DBI_select_db($GLOBALS['db']);
190 * returns default server collation from show variables
192 * @return string $server_collation
194 function PMA_getServerCollation() {
195 return PMA_DBI_fetch_value(
196 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1);
200 * returns description for given collation
203 * @param string $collation MySQL collation string
204 * @return string collation description
206 function PMA_getCollationDescr($collation) {
207 if ($collation == 'binary') {
210 $parts = explode('_', $collation);
211 if (count($parts) == 1) {
212 $parts[1] = 'general';
213 } elseif ($parts[1] == 'ci' ||
$parts[1] == 'cs') {
214 $parts[2] = $parts[1];
215 $parts[1] = 'general';
220 $descr = __('Bulgarian');
223 if ($parts[0] == 'gb2312' ||
$parts[0] == 'gbk') {
224 $descr = __('Simplified Chinese');
225 } elseif ($parts[0] == 'big5') {
226 $descr = __('Traditional Chinese');
230 $descr = __('case-insensitive');
233 $descr = __('case-sensitive');
236 $descr = __('Croatian');
239 $descr = __('Czech');
242 $descr = __('Danish');
245 $descr = __('English');
248 $descr = __('Esperanto');
251 $descr = __('Estonian');
254 $descr = __('German') . ' (' . __('dictionary') . ')';
257 $descr = __('German') . ' (' . __('phone book') . ')';
260 $descr = __('Hungarian');
263 $descr = __('Icelandic');
266 $descr = __('Japanese');
269 $descr = __('Latvian');
272 $descr = __('Lithuanian');
275 $descr = __('Korean');
278 $descr = __('Persian');
281 $descr = __('Polish');
284 $descr = __('West European');
287 $descr = __('Romanian');
290 $descr = __('Slovak');
293 $descr = __('Slovenian');
296 $descr = __('Spanish');
299 $descr = __('Traditional Spanish');
302 $descr = __('Swedish');
308 $descr = __('Turkish');
311 $descr = __('Ukrainian');
314 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
323 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
325 // West European charsets
332 $descr = __('West European') . ' (' . __('multilingual') . ')';
334 // Central European charsets
339 $descr = __('Central European') . ' (' . __('multilingual') . ')';
344 $descr = __('Russian');
346 // Simplified Chinese charsets
349 $descr = __('Simplified Chinese');
356 $descr = __('Japanese');
361 $descr = __('Baltic') . ' (' . __('multilingual') . ')';
366 $descr = __('Armenian');
369 $descr = __('Traditional Chinese');
372 $descr = __('Cyrillic') . ' (' . __('multilingual') . ')';
375 $descr = __('Arabic');
378 $descr = __('Korean');
381 $descr = __('Hebrew');
384 $descr = __('Georgian');
387 $descr = __('Greek');
390 $descr = __('Czech-Slovak');
393 $descr = __('Ukrainian');
396 $descr = __('Turkish');
399 $descr = __('Swedish');
405 $descr = __('unknown');
408 if (!empty($is_bin)) {
409 $descr .= ', ' . __('Binary');
412 default: $descr = __('unknown');
414 if (!empty($parts[2])) {
415 if ($parts[2] == 'ci') {
416 $descr .= ', ' . __('case-insensitive');
417 } elseif ($parts[2] == 'cs') {
418 $descr .= ', ' . __('case-sensitive');