2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Shared code for mysql charsets
8 if (! defined('PHPMYADMIN')) {
12 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION
,
13 $name = null, $id = null, $default = null, $label = true, $indent = 0,
14 $submitOnChange = false, $displayUnavailable = false
16 global $mysql_charsets, $mysql_charsets_descriptions,
17 $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
20 if ($type == PMA_CSDROPDOWN_COLLATION
) {
23 $name = 'character_set';
27 $return_str = '<select lang="en" dir="ltr" name="'
28 . htmlspecialchars($name) . '"'
29 . (empty($id) ?
'' : ' id="' . htmlspecialchars($id) . '"')
30 . ($submitOnChange ?
' class="autosubmit"' : '') . '>' . "\n";
32 $return_str .= '<option value="">'
33 . ($type == PMA_CSDROPDOWN_COLLATION ?
__('Collation') : __('Charset'))
36 $return_str .= '<option value=""></option>' . "\n";
37 foreach ($mysql_charsets as $current_charset) {
38 if (!$mysql_charsets_available[$current_charset]) {
42 = empty($mysql_charsets_descriptions[$current_charset])
44 : $mysql_charsets_descriptions[$current_charset];
46 if ($type == PMA_CSDROPDOWN_COLLATION
) {
47 $return_str .= '<optgroup label="' . $current_charset
48 . '" title="' . $current_cs_descr . '">' . "\n";
49 foreach ($mysql_collations[$current_charset] as $current_collation) {
50 if (!$mysql_collations_available[$current_collation]) {
53 $return_str .= '<option value="' . $current_collation
54 . '" title="' . PMA_getCollationDescr($current_collation) . '"'
55 . ($default == $current_collation ?
' selected="selected"' : '')
57 . $current_collation . '</option>' . "\n";
59 $return_str .= '</optgroup>' . "\n";
61 $return_str .= '<option value="' . $current_charset
62 . '" title="' . $current_cs_descr . '"'
63 . ($default == $current_charset ?
' selected="selected"' : '') . '>'
64 . $current_charset . '</option>' . "\n";
67 $return_str .= '</select>' . "\n";
72 function PMA_generateCharsetQueryPart($collation)
75 list($charset) = explode('_', $collation);
76 return ' CHARACTER SET ' . $charset
77 . ($charset == $collation ?
'' : ' COLLATE ' . $collation);
79 return ' COLLATE ' . $collation;
84 * returns collation of given db
86 * @param string $db name of db
88 * @return string collation of $db
90 function PMA_getDbCollation($db)
92 if ($GLOBALS['dbi']->isSystemSchema($db)) {
93 // We don't have to check the collation of the virtual
94 // information_schema database: We know it!
95 return 'utf8_general_ci';
98 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
99 // this is slow with thousands of databases
101 ?
'SELECT DEFAULT_COLLATION_NAME FROM data_dictionary.SCHEMAS'
102 . ' WHERE SCHEMA_NAME = \'' . PMA_Util
::sqlAddSlashes($db)
104 : 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA'
105 . ' WHERE SCHEMA_NAME = \'' . PMA_Util
::sqlAddSlashes($db)
107 return $GLOBALS['dbi']->fetchValue($sql);
109 $GLOBALS['dbi']->selectDb($db);
110 $return = $GLOBALS['dbi']->fetchValue(
111 'SHOW VARIABLES LIKE \'collation_database\'', 0, 1
113 if ($db !== $GLOBALS['db']) {
114 $GLOBALS['dbi']->selectDb($GLOBALS['db']);
121 * returns default server collation from show variables
123 * @return string $server_collation
125 function PMA_getServerCollation()
127 return $GLOBALS['dbi']->fetchValue(
128 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1
133 * returns description for given collation
135 * @param string $collation MySQL collation string
137 * @return string collation description
139 function PMA_getCollationDescr($collation)
141 if ($collation == 'binary') {
144 $parts = explode('_', $collation);
145 if (count($parts) == 1) {
146 $parts[1] = 'general';
147 } elseif ($parts[1] == 'ci' ||
$parts[1] == 'cs') {
148 $parts[2] = $parts[1];
149 $parts[1] = 'general';
154 $descr = __('Bulgarian');
157 if ($parts[0] == 'gb2312' ||
$parts[0] == 'gbk') {
158 $descr = __('Simplified Chinese');
159 } elseif ($parts[0] == 'big5') {
160 $descr = __('Traditional Chinese');
164 $descr = __('case-insensitive');
167 $descr = __('case-sensitive');
170 $descr = __('Croatian');
173 $descr = __('Czech');
176 $descr = __('Danish');
179 $descr = __('English');
182 $descr = __('Esperanto');
185 $descr = __('Estonian');
188 $descr = __('German') . ' (' . __('dictionary') . ')';
191 $descr = __('German') . ' (' . __('phone book') . ')';
194 $descr = __('Hungarian');
197 $descr = __('Icelandic');
200 $descr = __('Japanese');
203 $descr = __('Latvian');
206 $descr = __('Lithuanian');
209 $descr = __('Korean');
212 $descr = __('Persian');
215 $descr = __('Polish');
218 $descr = __('West European');
221 $descr = __('Romanian');
224 $descr = __('Slovak');
227 $descr = __('Slovenian');
230 $descr = __('Spanish');
233 $descr = __('Traditional Spanish');
236 $descr = __('Swedish');
242 $descr = __('Turkish');
245 $descr = __('Ukrainian');
248 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
258 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
260 // West European charsets
267 $descr = __('West European') . ' (' . __('multilingual') . ')';
269 // Central European charsets
274 $descr = __('Central European') . ' (' . __('multilingual') . ')';
279 $descr = __('Russian');
281 // Simplified Chinese charsets
284 $descr = __('Simplified Chinese');
291 $descr = __('Japanese');
296 $descr = __('Baltic') . ' (' . __('multilingual') . ')';
301 $descr = __('Armenian');
304 $descr = __('Traditional Chinese');
307 $descr = __('Cyrillic') . ' (' . __('multilingual') . ')';
310 $descr = __('Arabic');
313 $descr = __('Korean');
316 $descr = __('Hebrew');
319 $descr = __('Georgian');
322 $descr = __('Greek');
325 $descr = __('Czech-Slovak');
328 $descr = __('Ukrainian');
331 $descr = __('Turkish');
334 $descr = __('Swedish');
340 $descr = __('unknown');
343 if (!empty($is_bin)) {
344 $descr .= ', ' . __('Binary');
347 default: $descr = __('unknown');
349 if (!empty($parts[2])) {
350 if ($parts[2] == 'ci') {
351 $descr .= ', ' . __('case-insensitive');
352 } elseif ($parts[2] == 'cs') {
353 $descr .= ', ' . __('case-sensitive');