home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / mysql_charsets.lib.php < prev    next >
Encoding:
PHP Script  |  2004-06-06  |  9.9 KB  |  265 lines

  1. <?php
  2. /* $Id: mysql_charsets.lib.php,v 2.7.2.2 2004/06/07 10:09:53 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. if (PMA_MYSQL_INT_VERSION >= 40100){
  6.  
  7.     $res = PMA_mysql_query('SHOW CHARACTER SET;', $userlink)
  8.         or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW CHARACTER SET;');
  9.  
  10.     $mysql_charsets = array();
  11.     while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
  12.         $mysql_charsets[] = $row['Charset'];
  13.         $mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
  14.         $mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
  15.     }
  16.     @mysql_free_result($res);
  17.     unset($res, $row);
  18.  
  19.     $res = PMA_mysql_query('SHOW COLLATION;', $userlink)
  20.         or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW COLLATION;');
  21.  
  22.     $mysql_charsets_count = count($mysql_charsets);
  23.     sort($mysql_charsets, SORT_STRING);
  24.  
  25.     $mysql_collations = array_flip($mysql_charsets);
  26.     $mysql_default_collations = $mysql_collations_flat = array();;
  27.     while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
  28.         if (!is_array($mysql_collations[$row['Charset']])) {
  29.             $mysql_collations[$row['Charset']] = array($row['Collation']);
  30.         } else {
  31.             $mysql_collations[$row['Charset']][] = $row['Collation'];
  32.         }
  33.         $mysql_collations_flat[] = $row['Collation'];
  34.         if ((isset($row['D']) && $row['D'] == 'Y') || (isset($row['Default']) && $row['Default'] == 'Yes')) {
  35.             $mysql_default_collations[$row['Charset']] = $row['Collation'];
  36.         }
  37.     }
  38.  
  39.     $mysql_collations_count = count($mysql_collations_flat);
  40.     sort($mysql_collations_flat, SORT_STRING);
  41.     foreach($mysql_collations AS $key => $value) {
  42.         sort($mysql_collations[$key], SORT_STRING);
  43.         reset($mysql_collations[$key]);
  44.     }
  45.  
  46.     @mysql_free_result($res);
  47.     unset($res, $row);
  48.  
  49.     function PMA_getCollationDescr($collation) {
  50.         if ($collation == 'binary') {
  51.             return $GLOBALS['strBinary'];
  52.         }
  53.         $parts = explode('_', $collation);
  54.         if (count($parts) == 1) {
  55.             $parts[1] = 'general';
  56.         } elseif ($parts[1] == 'ci' || $parts[1] == 'cs') {
  57.             $parts[2] = $parts[1];
  58.             $parts[1] = 'general';
  59.         }
  60.         $descr = '';
  61.         switch ($parts[1]) {
  62.             case 'bulgarian':
  63.                 $descr = $GLOBALS['strBulgarian'];
  64.                 break;
  65.             case 'chinese':
  66.                 if ($parts[0] == 'gb2312' || $parts[0] == 'gbk') {
  67.                     $descr = $GLOBALS['strSimplifiedChinese'];
  68.                 } elseif ($parts[0] == 'big5') {
  69.                     $descr = $GLOBALS['strTraditionalChinese'];
  70.                 }
  71.                 break;
  72.             case 'ci':
  73.                 $descr = $GLOBALS['strCaseInsensitive'];
  74.                 break;
  75.             case 'cs':
  76.                 $descr = $GLOBALS['strCaseSensitive'];
  77.                 break;
  78.             case 'croatian':
  79.                 $descr = $GLOBALS['strCroatian'];
  80.                 break;
  81.             case 'czech':
  82.                 $descr = $GLOBALS['strCzech'];
  83.                 break;
  84.             case 'danish':
  85.                 $descr = $GLOBALS['strDanish'];
  86.                 break;
  87.             case 'english':
  88.                 $descr = $GLOBALS['strEnglish'];
  89.                 break;
  90.             case 'estonian':
  91.                 $descr = $GLOBALS['strEstonian'];
  92.                 break;
  93.             case 'german1':
  94.                 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strDictionary'] . ')';
  95.                 break;
  96.             case 'german2':
  97.                 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strPhoneBook'] . ')';
  98.                 break;
  99.             case 'hungarian':
  100.                 $descr = $GLOBALS['strHungarian'];
  101.                 break;
  102.             case 'japanese':
  103.                 $descr = $GLOBALS['strJapanese'];
  104.                 break;
  105.             case 'lithuanian':
  106.                 $descr = $GLOBALS['strLithuanian'];
  107.                 break;
  108.             case 'korean':
  109.                 $descr = $GLOBALS['strKorean'];
  110.                 break;
  111.             case 'spanish':
  112.                 $descr = $GLOBALS['strSpanish'];
  113.                 break;
  114.             case 'swedish':
  115.                 $descr = $GLOBALS['strSwedish'];
  116.                 break;
  117.             case 'thai':
  118.                 $descr = $GLOBALS['strThai'];
  119.                 break;
  120.             case 'turkish':
  121.                 $descr = $GLOBALS['strTurkish'];
  122.                 break;
  123.             case 'ukrainian':
  124.                 $descr = $GLOBALS['strUkrainian'];
  125.                 break;
  126.             case 'bin':
  127.                 $is_bin = TRUE;
  128.             case 'general':
  129.                 switch ($parts[0]) {
  130.                     // Unicode charsets
  131.                     case 'ucs2':
  132.                     case 'utf8':
  133.                         $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
  134.                         break;
  135.                     // West European charsets
  136.                     case 'ascii':
  137.                     case 'cp850':
  138.                     case 'dec8':
  139.                     case 'hp8':
  140.                     case 'latin1':
  141.                     case 'macroman':
  142.                         $descr = $GLOBALS['strWestEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
  143.                         break;
  144.                     // Central European charsets
  145.                     case 'cp1250':
  146.                     case 'cp852':
  147.                     case 'latin2':
  148.                     case 'macce':
  149.                         $descr = $GLOBALS['strCentralEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
  150.                         break;
  151.                     // Russian charsets
  152.                     case 'cp866':
  153.                     case 'koi8r':
  154.                         $descr = $GLOBALS['strRussian'];
  155.                         break;
  156.                     // Simplified Chinese charsets
  157.                     case 'gb2312':
  158.                     case 'gbk':
  159.                         $descr = $GLOBALS['strSimplifiedChinese'];
  160.                         break;
  161.                     // Japanese charsets
  162.                     case 'sjis':
  163.                     case 'ujis':
  164.                         $descr = $GLOBALS['strJapanese'];
  165.                         break;
  166.                     // Baltic charsets
  167.                     case 'cp1257':
  168.                     case 'latin7':
  169.                         $descr = $GLOBALS['strBaltic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
  170.                         break;
  171.                     // Other
  172.                     case 'armscii8':
  173.                     case 'armscii':
  174.                         $descr = $GLOBALS['strArmenian'];
  175.                         break;
  176.                     case 'big5':
  177.                         $descr = $GLOBALS['strTraditionalChinese'];
  178.                         break;
  179.                     case 'cp1251':
  180.                         $descr = $GLOBALS['strCyrillic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
  181.                         break;
  182.                     case 'cp1256':
  183.                         $descr = $GLOBALS['strArabic'];
  184.                         break;
  185.                     case 'euckr':
  186.                         $descr = $GLOBALS['strKorean'];
  187.                         break;
  188.                     case 'hebrew':
  189.                         $descr = $GLOBALS['strHebrew'];
  190.                         break;
  191.                     case 'geostd8':
  192.                         $descr = $GLOBALS['strGeorgian'];
  193.                         break;
  194.                     case 'greek':
  195.                         $descr = $GLOBALS['strGreek'];
  196.                         break;
  197.                     case 'keybcs2':
  198.                         $descr = $GLOBALS['strCzechSlovak'];
  199.                         break;
  200.                     case 'koi8u':
  201.                         $descr = $GLOBALS['strUkrainian'];
  202.                         break;
  203.                     case 'latin5':
  204.                         $descr = $GLOBALS['strTurkish'];
  205.                         break;
  206.                     case 'swe7':
  207.                         $descr = $GLOBALS['strSwedish'];
  208.                         break;
  209.                     case 'tis620':
  210.                         $descr = $GLOBALS['strThai'];
  211.                         break;
  212.                     default:
  213.                         $descr = $GLOBALS['strUnknown'];
  214.                         break;
  215.                 }
  216.                 if (!empty($is_bin)) {
  217.                     $descr .= ', ' . $GLOBALS['strBinary'];
  218.                 }
  219.                 break;
  220.             default: return '';
  221.         }
  222.         if (!empty($parts[2])) {
  223.             if ($parts[2] == 'ci') {
  224.                 $descr .= ', ' . $GLOBALS['strCaseInsensitive'];
  225.             } elseif ($parts[2] == 'cs') {
  226.                 $descr .= ', ' . $GLOBALS['strCaseSensitive'];
  227.             }
  228.         }
  229.         return $descr;
  230.     }
  231.  
  232.     function PMA_getDbCollation($db) {
  233.         global $userlink;
  234.  
  235.         if (PMA_MYSQL_INT_VERSION >= 40101) {
  236.             // MySQL 4.1.0 does not support seperate charset settings
  237.             // for databases.
  238.  
  239.             $sql_query = 'SHOW CREATE DATABASE ' . PMA_backquote($db) . ';';
  240.             $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  241.             $row = PMA_mysql_fetch_row($res);
  242.             mysql_free_result($res);
  243.             $tokenized = explode(' ', $row[1]);
  244.             unset($row, $res, $sql_query);
  245.  
  246.             for ($i = 1; $i + 3 < count($tokenized); $i++) {
  247.                 if ($tokenized[$i] == 'DEFAULT' && $tokenized[$i + 1] == 'CHARACTER' && $tokenized[$i + 2] == 'SET') {
  248.                     // We've found the character set!
  249.                     if (isset($tokenized[$i + 5]) && $tokenized[$i + 4] == 'COLLATE') {
  250.                         return $tokenized[$i + 5]; // We found the collation!
  251.                     } else {
  252.                         // We did not find the collation, so let's return the
  253.                         // default collation for the charset we've found.
  254.                         return $GLOBALS['mysql_default_collations'][$tokenized [$i + 3]];
  255.                     }
  256.                 }
  257.             }
  258.         }
  259.         return '';
  260.     }
  261.  
  262. }
  263.  
  264. ?>
  265.