Source for file locale.php

Documentation is available at locale.php

  1. #!/usr/local/bin/php
  2. <?php
  3. /**
  4.  * Examples how change the locale of MySQL messages and how to change the character set.
  5.  * @author Sascha 'SieGeL' Pfalz <php@saschapfalz.de>
  6.  * @package db_MySQL
  7.  * @subpackage Examples
  8.  * @version 0.36 (21-Sep-2008)
  9.  *  $Id: locale.php,v 1.1 2008/09/21 21:07:08 siegel Exp $
  10.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  11.  * @filesource
  12.  */
  13. /**
  14.  */
  15. require('functions.inc.php');
  16. $db new db_MySQL('./dbdefs.inc.php');
  17. $d WhichBR();
  18. if($d['SAPI'!= 'cli')
  19.   {
  20.   echo("<pre>\n");
  21.   }
  22.  
  23. echo($d['LF']."Locale & character set tests".$d['LF']);
  24. echo($d['HR']);
  25.  
  26. // First connect to the database:
  27.  
  28. $sock $db->Connect();
  29.  
  30. // Retrieve the current lc_time_names variable:
  31.  
  32. $current_locale $db->get_TimeNames();
  33. printf("Current Locale of MySQL connection is..........: '%s'%s",$current_locale$d['LF']);
  34.  
  35. // Now set it to english, no matter what is was previously, and check if right afterwards.
  36.  
  37. $db->set_TimeNames('en_US');
  38. printf("New locale after changing to english...........: '%s'%s",$db->get_TimeNames(),$d['LF']);
  39.  
  40. // Read the names of some dates in english:
  41.  
  42. $test_date '2008-09-21';
  43.  
  44. $eng_dates $db->Query("SELECT DATE_FORMAT('".$test_date."','%W %a %M %b') AS DF");
  45.  
  46. printf("Date '%s' formatted by MySQL in english: '%s'%s",$test_date,$eng_dates['DF'],$d['LF']);
  47.  
  48. // Now we switch to german and perform the same query again:
  49.  
  50. $db->set_TimeNames('de_DE');
  51. printf("New locale after changing to german............: '%s'%s",$db->get_TimeNames(),$d['LF']);
  52. $eng_dates $db->Query("SELECT DATE_FORMAT('".$test_date."','%W %a %M %b') AS DF");
  53.  
  54. printf("Date '%s' formatted by MySQL in german.: '%s'%s%s",$test_date,$eng_dates['DF'],$d['LF'],$d['LF']);
  55.  
  56. // Now we dump out the current settings for character set support:
  57.  
  58. echo("List of currently active character set settings for this MySQL connection.".$d['LF'].$d['LF']);
  59.  
  60. $current_charsets $db->get_CharSet();
  61. for($i 0$i count($current_charsets)$i++)
  62.   {
  63.   printf("%s%s: %s%s",$current_charsets[$i][0],str_repeat('.',(47-strlen($current_charsets[$i][0]))),$current_charsets[$i][1],$d['LF']);
  64.   }
  65. echo($d['LF'].'Now changing character set to utf8:'.$d['LF'].$d['LF']);
  66. $db->set_CharSet('utf8');
  67. $current_charsets $db->get_CharSet();
  68. for($i 0$i count($current_charsets)$i++)
  69.   {
  70.   printf("%s%s: %s%s",$current_charsets[$i][0],str_repeat('.',(47-strlen($current_charsets[$i][0]))),$current_charsets[$i][1],$d['LF']);
  71.   }
  72.  
  73. echo($d['LF'].$d['HR']);
  74. DBFooter($d['LF'],$db);
  75.  
  76. $db->Disconnect();
  77. if($d['SAPI'!= 'cli')
  78.   {
  79.   echo("</pre>\n");
  80.   }
  81. ?>

Documentation generated on Sat, 07 Aug 2010 10:18:11 +0200 by phpDocumentor 1.4.3