2 /* vim: set expandtab sw=4 ts=4 sts=4: */
7 if (! defined('PHPMYADMIN')) {
14 if (PMA_MYSQL_INT_VERSION
>= 40100){
16 $res = PMA_DBI_query('SHOW CHARACTER SET;');
18 $mysql_charsets = array();
19 while ($row = PMA_DBI_fetch_assoc($res)) {
20 $mysql_charsets[] = $row['Charset'];
22 //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
23 $mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
25 @PMA_DBI_free_result
($res);
27 $mysql_charsets_count = count($mysql_charsets);
28 sort($mysql_charsets, SORT_STRING
);
30 $mysql_collations = array_flip($mysql_charsets);
31 $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
33 $res = PMA_DBI_query('SHOW COLLATION;');
34 while ($row = PMA_DBI_fetch_assoc($res)) {
35 if (!is_array($mysql_collations[$row['Charset']])) {
36 $mysql_collations[$row['Charset']] = array($row['Collation']);
38 $mysql_collations[$row['Charset']][] = $row['Collation'];
40 $mysql_collations_flat[] = $row['Collation'];
41 if ((isset($row['D']) && $row['D'] == 'Y') ||
(isset($row['Default']) && $row['Default'] == 'Yes')) {
42 $mysql_default_collations[$row['Charset']] = $row['Collation'];
44 //$mysql_collations_available[$row['Collation']] = !isset($row['Compiled']) || $row['Compiled'] == 'Yes';
45 $mysql_collations_available[$row['Collation']] = TRUE;
46 $mysql_charsets_available[$row['Charset']] = !empty($mysql_charsets_available[$row['Charset']]) ||
!empty($mysql_collations_available[$row['Collation']]);
48 @PMA_DBI_free_result
($res);
51 $mysql_collations_count = count($mysql_collations_flat);
52 sort($mysql_collations_flat, SORT_STRING
);
53 foreach ($mysql_collations AS $key => $value) {
54 sort($mysql_collations[$key], SORT_STRING
);
55 reset($mysql_collations[$key]);
59 define('PMA_CSDROPDOWN_COLLATION', 0);
60 define('PMA_CSDROPDOWN_CHARSET', 1);
62 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION
, $name = null, $id = null, $default = null, $label = TRUE, $indent = 0, $submitOnChange = FALSE, $displayUnavailable = FALSE) {
63 global $mysql_charsets, $mysql_charsets_descriptions, $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
66 if ($type == PMA_CSDROPDOWN_COLLATION
) {
69 $name = 'character_set';
74 for ($i = 1; $i <= $indent; $i++
) $spacer .= ' ';
76 $return_str = $spacer . '<select xml:lang="en" dir="ltr" name="' . htmlspecialchars($name) . '"' . (empty($id) ?
'' : ' id="' . htmlspecialchars($id) . '"') . ($submitOnChange ?
' onchange="this.form.submit();"' : '') . '>' . "\n";
78 $return_str .= $spacer . ' <option value="">' . ($type == PMA_CSDROPDOWN_COLLATION ?
$GLOBALS['strCollation'] : $GLOBALS['strCharset']) . '</option>' . "\n";
80 $return_str .= $spacer . ' <option value=""> </option>' . "\n";
81 foreach ($mysql_charsets as $current_charset) {
82 if (!$mysql_charsets_available[$current_charset]) {
85 $current_cs_descr = empty($mysql_charsets_descriptions[$current_charset]) ?
$current_charset : $mysql_charsets_descriptions[$current_charset];
86 if ($type == PMA_CSDROPDOWN_COLLATION
) {
87 $return_str .= $spacer . ' <optgroup label="' . $current_charset . '" title="' . $current_cs_descr . '">' . "\n";
88 foreach ($mysql_collations[$current_charset] as $current_collation) {
89 if (!$mysql_collations_available[$current_collation]) {
92 $return_str .= $spacer . ' <option value="' . $current_collation . '" title="' . PMA_getCollationDescr($current_collation) . '"' . ($default == $current_collation ?
' selected="selected"' : '') . '>' . $current_collation . '</option>' . "\n";
94 $return_str .= $spacer . ' </optgroup>' . "\n";
96 $return_str .= $spacer . ' <option value="' . $current_charset . '" title="' . $current_cs_descr . '"' . ($default == $current_charset ?
' selected="selected"' : '') . '>' . $current_charset . '</option>' . "\n";
99 $return_str .= $spacer . '</select>' . "\n";
104 function PMA_generateCharsetQueryPart($collation) {
105 list($charset) = explode('_', $collation);
106 return ' CHARACTER SET ' . $charset . ($charset == $collation ?
'' : ' COLLATE ' . $collation);
110 * returns collation of given db
112 * @uses PMA_MYSQL_INT_VERSION
113 * @uses PMA_DBI_fetch_value()
114 * @uses PMA_DBI_select_db()
115 * @uses PMA_sqlAddSlashes()
116 * @uses $GLOBALS['db']
117 * @param string $db name of db
118 * @return string collation of $db
120 function PMA_getDbCollation($db) {
121 if (PMA_MYSQL_INT_VERSION
>= 50000 && $db == 'information_schema') {
122 // We don't have to check the collation of the virtual
123 // information_schema database: We know it!
124 return 'utf8_general_ci';
126 if (PMA_MYSQL_INT_VERSION
>= 50006) {
127 // Since MySQL 5.0.6, we don't have to parse SHOW CREATE DATABASE anymore.
128 return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;');
129 } elseif (PMA_MYSQL_INT_VERSION
>= 40101) {
130 // MySQL 4.1.0 does not support seperate charset settings
132 PMA_DBI_select_db($db);
133 // the query does not work if this string is in double quotes
134 // and MySQL is running in ANSI mode
135 $return = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'collation_database\'', 0, 1);
136 if ($db !== $GLOBALS['db']) {
137 PMA_DBI_select_db($GLOBALS['db']);
145 function PMA_getDbCollation($db) { return PMA_getServerCollation(); }
149 * returns default server collation from show variables
151 * @uses PMA_DBI_fetch_value()
152 * @return string $server_collation
154 function PMA_getServerCollation() {
155 return PMA_DBI_fetch_value(
156 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1);
160 * returns description for given collation
165 * @uses $GLOBALS['str[Languages|Sorting]']
167 * @param string $collation MySQL collation string
168 * @return string collation description
170 function PMA_getCollationDescr($collation) {
171 static $collation_cache;
173 if (!is_array($collation_cache)) {
174 $collation_cache = array();
175 } elseif (isset($collation_cache[$collation])) {
176 return $collation_cache[$collation];
179 if ($collation == 'binary') {
180 return $GLOBALS['strBinary'];
182 $parts = explode('_', $collation);
183 if (count($parts) == 1) {
184 $parts[1] = 'general';
185 } elseif ($parts[1] == 'ci' ||
$parts[1] == 'cs') {
186 $parts[2] = $parts[1];
187 $parts[1] = 'general';
192 $descr = $GLOBALS['strBulgarian'];
195 if ($parts[0] == 'gb2312' ||
$parts[0] == 'gbk') {
196 $descr = $GLOBALS['strSimplifiedChinese'];
197 } elseif ($parts[0] == 'big5') {
198 $descr = $GLOBALS['strTraditionalChinese'];
202 $descr = $GLOBALS['strCaseInsensitive'];
205 $descr = $GLOBALS['strCaseSensitive'];
208 $descr = $GLOBALS['strCroatian'];
211 $descr = $GLOBALS['strCzech'];
214 $descr = $GLOBALS['strDanish'];
217 $descr = $GLOBALS['strEnglish'];
220 $descr = $GLOBALS['strEsperanto'];
223 $descr = $GLOBALS['strEstonian'];
226 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strDictionary'] . ')';
229 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strPhoneBook'] . ')';
232 $descr = $GLOBALS['strHungarian'];
235 $descr = $GLOBALS['strIcelandic'];
238 $descr = $GLOBALS['strJapanese'];
241 $descr = $GLOBALS['strLatvian'];
244 $descr = $GLOBALS['strLithuanian'];
247 $descr = $GLOBALS['strKorean'];
250 $descr = $GLOBALS['strPersian'];
253 $descr = $GLOBALS['strPolish'];
256 $descr = $GLOBALS['strWestEuropean'];
259 $descr = $GLOBALS['strRomanian'];
262 $descr = $GLOBALS['strSlovak'];
265 $descr = $GLOBALS['strSlovenian'];
268 $descr = $GLOBALS['strSpanish'];
271 $descr = $GLOBALS['strTraditionalSpanish'];
274 $descr = $GLOBALS['strSwedish'];
277 $descr = $GLOBALS['strThai'];
280 $descr = $GLOBALS['strTurkish'];
283 $descr = $GLOBALS['strUkrainian'];
286 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
295 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
297 // West European charsets
304 $descr = $GLOBALS['strWestEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
306 // Central European charsets
311 $descr = $GLOBALS['strCentralEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
316 $descr = $GLOBALS['strRussian'];
318 // Simplified Chinese charsets
321 $descr = $GLOBALS['strSimplifiedChinese'];
328 $descr = $GLOBALS['strJapanese'];
333 $descr = $GLOBALS['strBaltic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
338 $descr = $GLOBALS['strArmenian'];
341 $descr = $GLOBALS['strTraditionalChinese'];
344 $descr = $GLOBALS['strCyrillic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
347 $descr = $GLOBALS['strArabic'];
350 $descr = $GLOBALS['strKorean'];
353 $descr = $GLOBALS['strHebrew'];
356 $descr = $GLOBALS['strGeorgian'];
359 $descr = $GLOBALS['strGreek'];
362 $descr = $GLOBALS['strCzechSlovak'];
365 $descr = $GLOBALS['strUkrainian'];
368 $descr = $GLOBALS['strTurkish'];
371 $descr = $GLOBALS['strSwedish'];
374 $descr = $GLOBALS['strThai'];
377 $descr = $GLOBALS['strUnknown'];
380 if (!empty($is_bin)) {
381 $descr .= ', ' . $GLOBALS['strBinary'];
384 default: $descr = $GLOBALS['strUnknown'];
386 if (!empty($parts[2])) {
387 if ($parts[2] == 'ci') {
388 $descr .= ', ' . $GLOBALS['strCaseInsensitive'];
389 } elseif ($parts[2] == 'cs') {
390 $descr .= ', ' . $GLOBALS['strCaseSensitive'];
394 $collation_cache[$collation] = $descr;