The multi-lingual support that was introduced from MySQL 4.1 is really great, and some features have overtaken other database systems. But I found in the test that using the PHP statement before MySQL 4.1 to manipulate the MySQL database can be garbled, even if the table character set is too.
The character set support for MySQL 4.1 (Character set supports) has two aspects: the character set (Character set) and the Sort method (Collation). Support for character sets is refined to four levels: server, database, data table (table), and connection (connection).
The settings for viewing the character set and ordering of the system 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 values listed above are the default values for the system. (It's strange how the system defaults to the Swedish sort method of Latin1.) )
When we access the MySQL database by PHP in the original way, even if the default character set of the table is UTF8 and the query is sent through UTF-8 encoding, you will find that the database is still garbled. The problem is on the connection connection layer. The workaround is to execute the following sentence before sending the query:
SET NAMES ' UTF8 ';
It is equivalent to the following three-sentence instruction:
SET character_set_client = UTF8;
SET character_set_results = UTF8;
SET character_set_connection = UTF8;
Try again, it's normal.
The above is to solve the PHP access MySQL 4.1 garbled problem content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!