From MySQL 4.1 introduced multi-language support is indeed great, and some properties more than the other database systems.But I found in the testing process used for MySQL 4.1 PHP statement before the operation will cause garbled MySQL database, even after a table is set the character set as well.
MySQL 4.1 character set support (Character Set Support) has two aspects: character set (Character set) and Sort (Collation).Support for character sets down to four levels: server (server), database (database), data table (table) and connection (connection).
View the system's character set and sort order can be set through the following two commands:
mysql> SHOW VARIABLES LIKE 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| Character_set_client | latin1 |
| Character_set_connection | latin1 |
| Character_set_database | latin1 |
| Character_set_results | latin1 |
| Character_set_server | latin1 |
| Character_set_system | utf8 |
| Character_sets_dir | / usr / share / mysql / charsets / |
+--------------------------+----------------------------+
7 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'collation_%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| Collation_connection | latin1_swedish_ci |
| Collation_database | latin1_swedish_ci |
| Collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)
The value listed above is the system default.(Very strange how the system default is latin1 sort in Swedish.)
When we adopted in accordance with the original PHP to access MySQL database, even if the table is set utf8 default character set is UTF-8 encoded and sent by check, you will find stored in the database is still garbled.The problem lies in the connection layer connection.Solution is to send queries about the following sentence before the execution:
SET NAMES 'utf8';
It is equivalent to the following three commands:
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;
Try again to normal.