Documentation TYPO3 par Ameos

mysql_charsets.lib.php

00001 <?php
00002 /* $Id: mysql_charsets.lib.php,v 2.7.2.1 2004/02/02 09:30:01 rabus Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 if (PMA_MYSQL_INT_VERSION >= 40100){
00006 
00007     $res = PMA_mysql_query('SHOW CHARACTER SET;', $userlink)
00008         or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW CHARACTER SET;');
00009 
00010     $mysql_charsets = array();
00011     while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
00012         $mysql_charsets[] = $row['Charset'];
00013         $mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
00014         $mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
00015     }
00016     @mysql_free_result($res);
00017     unset($res, $row);
00018 
00019     $res = PMA_mysql_query('SHOW COLLATION;', $userlink)
00020         or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW COLLATION;');
00021 
00022     $mysql_charsets_count = count($mysql_charsets);
00023     sort($mysql_charsets, SORT_STRING);
00024 
00025     $mysql_collations = array_flip($mysql_charsets);
00026     $mysql_default_collations = $mysql_collations_flat = array();;
00027     while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
00028         if (!is_array($mysql_collations[$row['Charset']])) {
00029             $mysql_collations[$row['Charset']] = array($row['Collation']);
00030         } else {
00031             $mysql_collations[$row['Charset']][] = $row['Collation'];
00032         }
00033         $mysql_collations_flat[] = $row['Collation'];
00034         if ((isset($row['D']) && $row['D'] == 'Y') || (isset($row['Default']) && $row['Default'] == 'Yes')) {
00035             $mysql_default_collations[$row['Charset']] = $row['Collation'];
00036         }
00037     }
00038 
00039     $mysql_collations_count = count($mysql_collations_flat);
00040     sort($mysql_collations_flat, SORT_STRING);
00041     foreach($mysql_collations AS $key => $value) {
00042         sort($mysql_collations[$key], SORT_STRING);
00043         reset($mysql_collations[$key]);
00044     }
00045 
00046     @mysql_free_result($res);
00047     unset($res, $row);
00048 
00049     function PMA_getCollationDescr($collation) {
00050         if ($collation == 'binary') {
00051             return $GLOBALS['strBinary'];
00052         }
00053         $parts = explode('_', $collation);
00054         if (count($parts) == 1) {
00055             $parts[1] = 'general';
00056         } elseif ($parts[1] == 'ci' || $parts[1] == 'cs') {
00057             $parts[2] = $parts[1];
00058             $parts[1] = 'general';
00059         }
00060         $descr = '';
00061         switch ($parts[1]) {
00062             case 'bulgarian':
00063                 $descr = $GLOBALS['strBulgarian'];
00064                 break;
00065             case 'chinese':
00066                 if ($parts[0] == 'gb2312' || $parts[0] == 'gbk') {
00067                     $descr = $GLOBALS['strSimplifiedChinese'];
00068                 } elseif ($parts[0] == 'big5') {
00069                     $descr = $GLOBALS['strTraditionalChinese'];
00070                 }
00071                 break;
00072             case 'ci':
00073                 $descr = $GLOBALS['strCaseInsensitive'];
00074                 break;
00075             case 'cs':
00076                 $descr = $GLOBALS['strCaseSensitive'];
00077                 break;
00078             case 'croatian':
00079                 $descr = $GLOBALS['strCroatian'];
00080                 break;
00081             case 'czech':
00082                 $descr = $GLOBALS['strCzech'];
00083                 break;
00084             case 'danish':
00085                 $descr = $GLOBALS['strDanish'];
00086                 break;
00087             case 'english':
00088                 $descr = $GLOBALS['strEnglish'];
00089                 break;
00090             case 'estonian':
00091                 $descr = $GLOBALS['strEstonian'];
00092                 break;
00093             case 'german1':
00094                 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strDictionary'] . ')';
00095                 break;
00096             case 'german2':
00097                 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strPhoneBook'] . ')';
00098                 break;
00099             case 'hungarian':
00100                 $descr = $GLOBALS['strHungarian'];
00101                 break;
00102             case 'japanese':
00103                 $descr = $GLOBALS['strJapanese'];
00104                 break;
00105             case 'lithuanian':
00106                 $descr = $GLOBALS['strLithuanian'];
00107                 break;
00108             case 'korean':
00109                 $descr = $GLOBALS['strKorean'];
00110                 break;
00111             case 'swedish':
00112                 $descr = $GLOBALS['strSwedish'];
00113                 break;
00114             case 'thai':
00115                 $descr = $GLOBALS['strThai'];
00116                 break;
00117             case 'turkish':
00118                 $descr = $GLOBALS['strTurkish'];
00119                 break;
00120             case 'ukrainian':
00121                 $descr = $GLOBALS['strUkrainian'];
00122                 break;
00123             case 'bin':
00124                 $is_bin = TRUE;
00125             case 'general':
00126                 switch ($parts[0]) {
00127                     // Unicode charsets
00128                     case 'ucs2':
00129                     case 'utf8':
00130                         $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
00131                         break;
00132                     // West European charsets
00133                     case 'ascii':
00134                     case 'cp850':
00135                     case 'dec8':
00136                     case 'hp8':
00137                     case 'latin1':
00138                     case 'macroman':
00139                         $descr = $GLOBALS['strWestEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
00140                         break;
00141                     // Central European charsets
00142                     case 'cp1250':
00143                     case 'cp852':
00144                     case 'latin2':
00145                     case 'macce':
00146                         $descr = $GLOBALS['strCentralEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
00147                         break;
00148                     // Russian charsets
00149                     case 'cp866':
00150                     case 'koi8r':
00151                         $descr = $GLOBALS['strRussian'];
00152                         break;
00153                     // Simplified Chinese charsets
00154                     case 'gb2312':
00155                     case 'gbk':
00156                         $descr = $GLOBALS['strSimplifiedChinese'];
00157                         break;
00158                     // Japanese charsets
00159                     case 'sjis':
00160                     case 'ujis':
00161                         $descr = $GLOBALS['strJapanese'];
00162                         break;
00163                     // Baltic charsets
00164                     case 'cp1257':
00165                     case 'latin7':
00166                         $descr = $GLOBALS['strBaltic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
00167                         break;
00168                     // Other
00169                     case 'armscii8':
00170                     case 'armscii':
00171                         $descr = $GLOBALS['strArmenian'];
00172                         break;
00173                     case 'big5':
00174                         $descr = $GLOBALS['strTraditionalChinese'];
00175                         break;
00176                     case 'cp1251':
00177                         $descr = $GLOBALS['strCyrillic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
00178                         break;
00179                     case 'cp1256':
00180                         $descr = $GLOBALS['strArabic'];
00181                         break;
00182                     case 'euckr':
00183                         $descr = $GLOBALS['strKorean'];
00184                         break;
00185                     case 'hebrew':
00186                         $descr = $GLOBALS['strHebrew'];
00187                         break;
00188                     case 'geostd8':
00189                         $descr = $GLOBALS['strGeorgian'];
00190                         break;
00191                     case 'greek':
00192                         $descr = $GLOBALS['strGreek'];
00193                         break;
00194                     case 'keybcs2':
00195                         $descr = $GLOBALS['strCzechSlovak'];
00196                         break;
00197                     case 'koi8u':
00198                         $descr = $GLOBALS['strUkrainian'];
00199                         break;
00200                     case 'latin5':
00201                         $descr = $GLOBALS['strTurkish'];
00202                         break;
00203                     case 'swe7':
00204                         $descr = $GLOBALS['strSwedish'];
00205                         break;
00206                     case 'tis620':
00207                         $descr = $GLOBALS['strThai'];
00208                         break;
00209                     default:
00210                         $descr = $GLOBALS['strUnknown'];
00211                         break;
00212                 }
00213                 if (!empty($is_bin)) {
00214                     $descr .= ', ' . $GLOBALS['strBinary'];
00215                 }
00216                 break;
00217             default: return '';
00218         }
00219         if (!empty($parts[2])) {
00220             if ($parts[2] == 'ci') {
00221                 $descr .= ', ' . $GLOBALS['strCaseInsensitive'];
00222             } elseif ($parts[2] == 'cs') {
00223                 $descr .= ', ' . $GLOBALS['strCaseSensitive'];
00224             }
00225         }
00226         return $descr;
00227     }
00228 
00229     function PMA_getDbCollation($db) {
00230         global $userlink;
00231 
00232         if (PMA_MYSQL_INT_VERSION >= 40101) {
00233             // MySQL 4.1.0 does not support seperate charset settings
00234             // for databases.
00235 
00236             $sql_query = 'SHOW CREATE DATABASE ' . PMA_backquote($db) . ';';
00237             $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
00238             $row = PMA_mysql_fetch_row($res);
00239             mysql_free_result($res);
00240             $tokenized = explode(' ', $row[1]);
00241             unset($row, $res, $sql_query);
00242 
00243             for ($i = 1; $i + 3 < count($tokenized); $i++) {
00244                 if ($tokenized[$i] == 'DEFAULT' && $tokenized[$i + 1] == 'CHARACTER' && $tokenized[$i + 2] == 'SET') {
00245                     // We've found the character set!
00246                     if (isset($tokenized[$i + 5]) && $tokenized[$i + 4] == 'COLLATE') {
00247                         return $tokenized[$i + 5]; // We found the collation!
00248                     } else {
00249                         // We did not find the collation, so let's return the
00250                         // default collation for the charset we've found.
00251                         return $GLOBALS['mysql_default_collations'][$tokenized [$i + 3]];
00252                     }
00253                 }
00254             }
00255         }
00256         return '';
00257     }
00258 
00259 }
00260 
00261 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6