Charset Changing: Difference between revisions

From The Uniform Server Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
If you need another character set in your dynamics application then the Uniserver default one (ISO-8859-1 i.e. latin1) is, it is necessary to make approprite changes in Apache, MySQL an PHP code.
This wiki article will help you change your CHARacter SET to something else other than the default Uniform Server setting (ISO-8859-1 / latin1.)
I will demonstrate changes on the example where cp1250 is the final result.


1. Apache
In this article, our goal is to set the charset to '''cp1250'''
In the file local\Apache2\conf\httpd.conf
find the statement
AddDefaultCharset iso-8859-1
and change it to
AddCharset WINDOWS-1250 .cp-1250  .win-1250
save changes
Note: see ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets for the official list of charset names and their respective RFCs


==Apache==
# Find this statement in the Apache configuration file (W:/local/apache2/conf/httpd.conf) <pre>AddDefaultCharset iso-8859-1</pre> and change it to: <pre>AddCharset WINDOWS-1250 .cp-1250 .win-1250</pre> ''Note: See ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets for the official list of charset names and their respective RFCs.''


2. MySQL
==MySQL==
In the file \user\local\mysql\bin\my_small.cnf
# In the file (W:/user/local/mysql/bin/my_small.cnf) find line: <pre>??</pre>
find line
# Uncomment the following if you are NOT using BDB tables: <pre>??</pre>
# Uncomment the following if you are NOT using BDB tables
# Insert the two following lines: <pre>??</pre>
and BEFORE this line insert the two following lines.
# BEFORE this line: <pre> ??</pre>
save changes
# Restart Apache and MySQL and verify that system variables looks like this: <pre><nowiki>character set client latin1 cp1250
 
3. restart Apache and MySQL and verify that system variables looks like this
...
character set client latin1 cp1250
character set connection cp1250 cp1250
character set connection cp1250 cp1250
character set database cp1250 cp1250
character set database cp1250 cp1250
Line 29: Line 19:
collation connection cp1250_czech_cs cp1250_general_ci
collation connection cp1250_czech_cs cp1250_general_ci
collation database cp1250_general_ci cp1250_general_ci
collation database cp1250_general_ci cp1250_general_ci
collation server cp1250_general_ci cp1250_general_ci
collation server cp1250_general_ci cp1250_general_ci</nowiki></pre>
...
 
 
The lines where latin1 set remains is of no interest for us just now.
The lines where latin1 set remains is of no interest for us just now.
From know all databases will be corectly set to cp1250 and your dynamics data are presented in the new character set.
From now all databases will be correctly set to cp1250 and your dynamic data will be presented in the new character set.  
Note: should there are old application databases they are not automatically rcoded into the new char set. You should do it "manually" prefarably via phpMyAdmin.
 
''Note 1: There might be old application databases that are not automatically recorded into the new charset. You should do it "manually" prefarably via phpMyAdmin.''


But it does not generally mean that your application sends correctly formatted data into the database!!! And if they are not correctly sent they can't be later correctly presented in your browser. So you have to adjust PHP application now!
''Note 2: This does not generally mean that your application will send correctly formatted data into the database! If they are not sent correctly, they can later be presented correctly in your browser so you have to adjust the PHP application now!''


4. PHP
==PHP==
You have to find php definition file. That is the file where global interraction with MySQL is set. Look for the name like definition.php or so...
If you have a PHP definition or configuration file, the file where global interraction with MySQL is set, (look for a filename like: definition.php, cofig.php, etc.) in the "appropriate" place (you have to find the place yourself,) insert two lines of code: <pre>mysql_query("SET character_set_connection=cp1250");
In an "appropriate" place (you have to find the place yourself!!!)
mysql_query("SET character_set_client=cp1250");</pre>
insert two lines of code
mysql_query("SET character_set_connection=cp1250");
mysql_query("SET character_set_client=cp1250");

Revision as of 05:06, 17 November 2005

This wiki article will help you change your CHARacter SET to something else other than the default Uniform Server setting (ISO-8859-1 / latin1.)

In this article, our goal is to set the charset to cp1250

Apache

  1. Find this statement in the Apache configuration file (W:/local/apache2/conf/httpd.conf)
    AddDefaultCharset iso-8859-1
    and change it to:
    AddCharset WINDOWS-1250 .cp-1250 .win-1250
    Note: See ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets for the official list of charset names and their respective RFCs.

MySQL

  1. In the file (W:/user/local/mysql/bin/my_small.cnf) find line:
    ??
  2. Uncomment the following if you are NOT using BDB tables:
    ??
  3. Insert the two following lines:
    ??
  4. BEFORE this line:
     ??
  5. Restart Apache and MySQL and verify that system variables looks like this:
    character set client latin1 cp1250

character set connection cp1250 cp1250 character set database cp1250 cp1250 character set results latin1 cp1250 character set server cp1250 cp1250 character set system utf8 utf8 collation connection cp1250_czech_cs cp1250_general_ci collation database cp1250_general_ci cp1250_general_ci collation server cp1250_general_ci cp1250_general_ci


The lines where latin1 set remains is of no interest for us just now. From now all databases will be correctly set to cp1250 and your dynamic data will be presented in the new character set.

Note 1: There might be old application databases that are not automatically recorded into the new charset. You should do it "manually" prefarably via phpMyAdmin.

Note 2: This does not generally mean that your application will send correctly formatted data into the database! If they are not sent correctly, they can later be presented correctly in your browser so you have to adjust the PHP application now!

PHP

If you have a PHP definition or configuration file, the file where global interraction with MySQL is set, (look for a filename like: definition.php, cofig.php, etc.) in the "appropriate" place (you have to find the place yourself,) insert two lines of code:

mysql_query("SET character_set_connection=cp1250");
mysql_query("SET character_set_client=cp1250");