2 /* vim: set expandtab sw=4 ts=4 sts=4: */
11 if (PMA_MYSQL_INT_VERSION
>= 40100){
13 $res = PMA_DBI_query('SHOW CHARACTER SET;');
15 $mysql_charsets = array();
16 while ($row = PMA_DBI_fetch_assoc($res)) {
17 $mysql_charsets[] = $row['Charset'];
19 //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
20 $mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
22 @PMA_DBI_free_result
($res);
24 $mysql_charsets_count = count($mysql_charsets);
25 sort($mysql_charsets, SORT_STRING
);
27 $mysql_collations = array_flip($mysql_charsets);
28 $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
30 $res = PMA_DBI_query('SHOW COLLATION;');
31 while ($row = PMA_DBI_fetch_assoc($res)) {
32 if (!is_array($mysql_collations[$row['Charset']])) {
33 $mysql_collations[$row['Charset']] = array($row['Collation']);
35 $mysql_collations[$row['Charset']][] = $row['Collation'];
37 $mysql_collations_flat[] = $row['Collation'];
38 if ((isset($row['D']) && $row['D'] == 'Y') ||
(isset($row['Default']) && $row['Default'] == 'Yes')) {
39 $mysql_default_collations[$row['Charset']] = $row['Collation'];
41 //$mysql_collations_available[$row['Collation']] = !isset($row['Compiled']) || $row['Compiled'] == 'Yes';
42 $mysql_collations_available[$row['Collation']] = TRUE;
43 $mysql_charsets_available[$row['Charset']] = !empty($mysql_charsets_available[$row['Charset']]) ||
!empty($mysql_collations_available[$row['Collation']]);
45 @PMA_DBI_free_result
($res);
48 $mysql_collations_count = count($mysql_collations_flat);
49 sort($mysql_collations_flat, SORT_STRING
);
50 foreach ($mysql_collations AS $key => $value) {
51 sort($mysql_collations[$key], SORT_STRING
);
52 reset($mysql_collations[$key]);
56 define('PMA_CSDROPDOWN_COLLATION', 0);
57 define('PMA_CSDROPDOWN_CHARSET', 1);
59 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION
, $name = null, $id = null, $default = null, $label = TRUE, $indent = 0, $submitOnChange = FALSE, $displayUnavailable = FALSE) {
60 global $mysql_charsets, $mysql_charsets_descriptions, $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
63 if ($type == PMA_CSDROPDOWN_COLLATION
) {
66 $name = 'character_set';
71 for ($i = 1; $i <= $indent; $i++
) $spacer .= ' ';
73 $return_str = $spacer . '<select xml:lang="en" dir="ltr" name="' . htmlspecialchars($name) . '"' . (empty($id) ?
'' : ' id="' . htmlspecialchars($id) . '"') . ($submitOnChange ?
' onchange="this.form.submit();"' : '') . '>' . "\n";
75 $return_str .= $spacer . ' <option value="">' . ($type == PMA_CSDROPDOWN_COLLATION ?
$GLOBALS['strCollation'] : $GLOBALS['strCharset']) . '</option>' . "\n";
77 $return_str .= $spacer . ' <option value=""> </option>' . "\n";
78 foreach ($mysql_charsets as $current_charset) {
79 if (!$mysql_charsets_available[$current_charset]) {
82 $current_cs_descr = empty($mysql_charsets_descriptions[$current_charset]) ?
$current_charset : $mysql_charsets_descriptions[$current_charset];
83 if ($type == PMA_CSDROPDOWN_COLLATION
) {
84 $return_str .= $spacer . ' <optgroup label="' . $current_charset . '" title="' . $current_cs_descr . '">' . "\n";
85 foreach ($mysql_collations[$current_charset] as $current_collation) {
86 if (!$mysql_collations_available[$current_collation]) {
89 $return_str .= $spacer . ' <option value="' . $current_collation . '" title="' . PMA_getCollationDescr($current_collation) . '"' . ($default == $current_collation ?
' selected="selected"' : '') . '>' . $current_collation . '</option>' . "\n";
91 $return_str .= $spacer . ' </optgroup>' . "\n";
93 $return_str .= $spacer . ' <option value="' . $current_charset . '" title="' . $current_cs_descr . '"' . ($default == $current_charset ?
' selected="selected"' : '') . '>' . $current_charset . '</option>' . "\n";
96 $return_str .= $spacer . '</select>' . "\n";
101 function PMA_generateCharsetQueryPart($collation) {
102 list($charset) = explode('_', $collation);
103 return ' CHARACTER SET ' . $charset . ($charset == $collation ?
'' : ' COLLATE ' . $collation);
107 * returns collation of given db
109 * @uses PMA_MYSQL_INT_VERSION
110 * @uses PMA_DBI_fetch_value()
111 * @uses PMA_DBI_select_db()
112 * @uses PMA_sqlAddSlashes()
113 * @uses $GLOBALS['db']
114 * @param string $db name of db
115 * @return string collation of $db
117 function PMA_getDbCollation($db) {
118 if (PMA_MYSQL_INT_VERSION
>= 50000 && $db == 'information_schema') {
119 // We don't have to check the collation of the virtual
120 // information_schema database: We know it!
121 return 'utf8_general_ci';
123 if (PMA_MYSQL_INT_VERSION
>= 50006) {
124 // Since MySQL 5.0.6, we don't have to parse SHOW CREATE DATABASE anymore.
125 return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;');
126 } elseif (PMA_MYSQL_INT_VERSION
>= 40101) {
127 // MySQL 4.1.0 does not support seperate charset settings
129 PMA_DBI_select_db($db);
130 // the query does not work if this string is in double quotes
131 // and MySQL is running in ANSI mode
132 $return = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'collation_database\'', 0, 1);
133 if ($db !== $GLOBALS['db']) {
134 PMA_DBI_select_db($GLOBALS['db']);
142 function PMA_getDbCollation($db) { return PMA_getServerCollation(); }
146 * returns default server collation from show variables
148 * @uses PMA_DBI_fetch_value()
149 * @return string $server_collation
151 function PMA_getServerCollation() {
152 return PMA_DBI_fetch_value(
153 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1);
157 * returns description for given collation
162 * @uses $GLOBALS['str[Languages|Sorting]']
164 * @param string $collation MySQL collation string
165 * @return string collation description
167 function PMA_getCollationDescr($collation) {
168 static $collation_cache;
170 if (!is_array($collation_cache)) {
171 $collation_cache = array();
172 } elseif (isset($collation_cache[$collation])) {
173 return $collation_cache[$collation];
176 if ($collation == 'binary') {
177 return $GLOBALS['strBinary'];
179 $parts = explode('_', $collation);
180 if (count($parts) == 1) {
181 $parts[1] = 'general';
182 } elseif ($parts[1] == 'ci' ||
$parts[1] == 'cs') {
183 $parts[2] = $parts[1];
184 $parts[1] = 'general';
189 $descr = $GLOBALS['strBulgarian'];
192 if ($parts[0] == 'gb2312' ||
$parts[0] == 'gbk') {
193 $descr = $GLOBALS['strSimplifiedChinese'];
194 } elseif ($parts[0] == 'big5') {
195 $descr = $GLOBALS['strTraditionalChinese'];
199 $descr = $GLOBALS['strCaseInsensitive'];
202 $descr = $GLOBALS['strCaseSensitive'];
205 $descr = $GLOBALS['strCroatian'];
208 $descr = $GLOBALS['strCzech'];
211 $descr = $GLOBALS['strDanish'];
214 $descr = $GLOBALS['strEnglish'];
217 $descr = $GLOBALS['strEsperanto'];
220 $descr = $GLOBALS['strEstonian'];
223 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strDictionary'] . ')';
226 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strPhoneBook'] . ')';
229 $descr = $GLOBALS['strHungarian'];
232 $descr = $GLOBALS['strIcelandic'];
235 $descr = $GLOBALS['strJapanese'];
238 $descr = $GLOBALS['strLatvian'];
241 $descr = $GLOBALS['strLithuanian'];
244 $descr = $GLOBALS['strKorean'];
247 $descr = $GLOBALS['strPersian'];
250 $descr = $GLOBALS['strPolish'];
253 $descr = $GLOBALS['strWestEuropean'];
256 $descr = $GLOBALS['strRomanian'];
259 $descr = $GLOBALS['strSlovak'];
262 $descr = $GLOBALS['strSlovenian'];
265 $descr = $GLOBALS['strSpanish'];
268 $descr = $GLOBALS['strTraditionalSpanish'];
271 $descr = $GLOBALS['strSwedish'];
274 $descr = $GLOBALS['strThai'];
277 $descr = $GLOBALS['strTurkish'];
280 $descr = $GLOBALS['strUkrainian'];
283 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
292 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
294 // West European charsets
301 $descr = $GLOBALS['strWestEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
303 // Central European charsets
308 $descr = $GLOBALS['strCentralEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
313 $descr = $GLOBALS['strRussian'];
315 // Simplified Chinese charsets
318 $descr = $GLOBALS['strSimplifiedChinese'];
325 $descr = $GLOBALS['strJapanese'];
330 $descr = $GLOBALS['strBaltic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
335 $descr = $GLOBALS['strArmenian'];
338 $descr = $GLOBALS['strTraditionalChinese'];
341 $descr = $GLOBALS['strCyrillic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
344 $descr = $GLOBALS['strArabic'];
347 $descr = $GLOBALS['strKorean'];
350 $descr = $GLOBALS['strHebrew'];
353 $descr = $GLOBALS['strGeorgian'];
356 $descr = $GLOBALS['strGreek'];
359 $descr = $GLOBALS['strCzechSlovak'];
362 $descr = $GLOBALS['strUkrainian'];
365 $descr = $GLOBALS['strTurkish'];
368 $descr = $GLOBALS['strSwedish'];
371 $descr = $GLOBALS['strThai'];
374 $descr = $GLOBALS['strUnknown'];
377 if (!empty($is_bin)) {
378 $descr .= ', ' . $GLOBALS['strBinary'];
381 default: $descr = $GLOBALS['strUnknown'];
383 if (!empty($parts[2])) {
384 if ($parts[2] == 'ci') {
385 $descr .= ', ' . $GLOBALS['strCaseInsensitive'];
386 } elseif ($parts[2] == 'cs') {
387 $descr .= ', ' . $GLOBALS['strCaseSensitive'];
391 $collation_cache[$collation] = $descr;