2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Shared code for mysql charsets
8 if (! defined('PHPMYADMIN')) {
13 * Generate charset dropdown box
15 * @param int $type Type
16 * @param string $name Element name
17 * @param string $id Element id
18 * @param null|string $default Default value
19 * @param bool $label Label
20 * @param bool $submitOnChange Submit on change
24 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION
,
25 $name = null, $id = null, $default = null, $label = true,
26 $submitOnChange = false
28 global $mysql_charsets, $mysql_charsets_descriptions,
29 $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
32 if ($type == PMA_CSDROPDOWN_COLLATION
) {
35 $name = 'character_set';
39 $return_str = '<select lang="en" dir="ltr" name="'
40 . htmlspecialchars($name) . '"'
41 . (empty($id) ?
'' : ' id="' . htmlspecialchars($id) . '"')
42 . ($submitOnChange ?
' class="autosubmit"' : '') . '>' . "\n";
44 $return_str .= '<option value="">'
45 . ($type == PMA_CSDROPDOWN_COLLATION ?
__('Collation') : __('Charset'))
48 $return_str .= '<option value=""></option>' . "\n";
49 foreach ($mysql_charsets as $current_charset) {
50 if (!$mysql_charsets_available[$current_charset]) {
54 = empty($mysql_charsets_descriptions[$current_charset])
56 : $mysql_charsets_descriptions[$current_charset];
58 if ($type == PMA_CSDROPDOWN_COLLATION
) {
59 $return_str .= '<optgroup label="' . $current_charset
60 . '" title="' . $current_cs_descr . '">' . "\n";
61 foreach ($mysql_collations[$current_charset] as $current_collation) {
62 if (!$mysql_collations_available[$current_collation]) {
65 $return_str .= '<option value="' . $current_collation
66 . '" title="' . PMA_getCollationDescr($current_collation) . '"'
67 . ($default == $current_collation ?
' selected="selected"' : '')
69 . $current_collation . '</option>' . "\n";
71 $return_str .= '</optgroup>' . "\n";
73 $return_str .= '<option value="' . $current_charset
74 . '" title="' . $current_cs_descr . '"'
75 . ($default == $current_charset ?
' selected="selected"' : '') . '>'
76 . $current_charset . '</option>' . "\n";
79 $return_str .= '</select>' . "\n";
85 * Generate the charset query part
87 * @param string $collation Collation
91 function PMA_generateCharsetQueryPart($collation)
94 list($charset) = explode('_', $collation);
95 return ' CHARACTER SET ' . $charset
96 . ($charset == $collation ?
'' : ' COLLATE ' . $collation);
98 return ' COLLATE ' . $collation;
103 * returns collation of given db
105 * @param string $db name of db
107 * @return string collation of $db
109 function PMA_getDbCollation($db)
111 if ($GLOBALS['dbi']->isSystemSchema($db)) {
112 // We don't have to check the collation of the virtual
113 // information_schema database: We know it!
114 return 'utf8_general_ci';
117 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
118 // this is slow with thousands of databases
120 ?
'SELECT DEFAULT_COLLATION_NAME FROM data_dictionary.SCHEMAS'
121 . ' WHERE SCHEMA_NAME = \'' . PMA_Util
::sqlAddSlashes($db)
123 : 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA'
124 . ' WHERE SCHEMA_NAME = \'' . PMA_Util
::sqlAddSlashes($db)
126 return $GLOBALS['dbi']->fetchValue($sql);
128 $GLOBALS['dbi']->selectDb($db);
129 $return = $GLOBALS['dbi']->fetchValue(
130 'SHOW VARIABLES LIKE \'collation_database\'', 0, 1
132 if ($db !== $GLOBALS['db']) {
133 $GLOBALS['dbi']->selectDb($GLOBALS['db']);
140 * returns default server collation from show variables
142 * @return string $server_collation
144 function PMA_getServerCollation()
146 return $GLOBALS['dbi']->fetchValue(
147 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1
152 * returns description for given collation
154 * @param string $collation MySQL collation string
156 * @return string collation description
158 function PMA_getCollationDescr($collation)
160 if ($collation == 'binary') {
163 $parts = explode('_', $collation);
164 if (count($parts) == 1) {
165 $parts[1] = 'general';
166 } elseif ($parts[1] == 'ci' ||
$parts[1] == 'cs') {
167 $parts[2] = $parts[1];
168 $parts[1] = 'general';
173 $descr = __('Bulgarian');
176 if ($parts[0] == 'gb2312' ||
$parts[0] == 'gbk') {
177 $descr = __('Simplified Chinese');
178 } elseif ($parts[0] == 'big5') {
179 $descr = __('Traditional Chinese');
183 $descr = __('case-insensitive');
186 $descr = __('case-sensitive');
189 $descr = __('Croatian');
192 $descr = __('Czech');
195 $descr = __('Danish');
198 $descr = __('English');
201 $descr = __('Esperanto');
204 $descr = __('Estonian');
207 $descr = __('German') . ' (' . __('dictionary') . ')';
210 $descr = __('German') . ' (' . __('phone book') . ')';
213 $descr = __('Hungarian');
216 $descr = __('Icelandic');
219 $descr = __('Japanese');
222 $descr = __('Latvian');
225 $descr = __('Lithuanian');
228 $descr = __('Korean');
231 $descr = __('Persian');
234 $descr = __('Polish');
237 $descr = __('West European');
240 $descr = __('Romanian');
243 $descr = __('Sinhalese');
246 $descr = __('Slovak');
249 $descr = __('Slovenian');
252 $descr = __('Spanish');
255 $descr = __('Traditional Spanish');
258 $descr = __('Swedish');
264 $descr = __('Turkish');
267 $descr = __('Ukrainian');
270 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
273 $descr = __('Vietnamese');
277 // no break; statement here, continuing with 'general' section:
284 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
286 // West European charsets
293 $descr = __('West European') . ' (' . __('multilingual') . ')';
295 // Central European charsets
300 $descr = __('Central European') . ' (' . __('multilingual') . ')';
305 $descr = __('Russian');
307 // Simplified Chinese charsets
310 $descr = __('Simplified Chinese');
317 $descr = __('Japanese');
322 $descr = __('Baltic') . ' (' . __('multilingual') . ')';
327 $descr = __('Armenian');
330 $descr = __('Traditional Chinese');
333 $descr = __('Cyrillic') . ' (' . __('multilingual') . ')';
336 $descr = __('Arabic');
339 $descr = __('Korean');
342 $descr = __('Hebrew');
345 $descr = __('Georgian');
348 $descr = __('Greek');
351 $descr = __('Czech-Slovak');
354 $descr = __('Ukrainian');
357 $descr = __('Turkish');
360 $descr = __('Swedish');
366 $descr = __('unknown');
369 if (!empty($is_bin)) {
370 $descr .= ', ' . __('Binary');
373 default: $descr = __('unknown');
375 if (!empty($parts[2])) {
376 if ($parts[2] == 'ci') {
377 $descr .= ', ' . __('case-insensitive');
378 } elseif ($parts[2] == 'cs') {
379 $descr .= ', ' . __('case-sensitive');