Read a lot of articles, most just talk about how to operate, do not involve the principle, is very disappointed, like headless flies as a random collision.
First look at the character sets involved in the Php+mysql+apache environment:
Describes the database internal storage character set:
The "database internal storage Character Set" refers to what encoding the data is stored in the database. Includes three types of granular character sets: Server character set, database character set, and database table character set. The priority of these three sets of characters is higher, and the database table character set has precedence over the database character set larger than the server character set.
Character_set_server/default_character_setrefers to the server character set;Character_set_databaserefers to the database character set;character_set_tablerefers to the database table character set.
Describes the client-side request character set and the request result character set:
Character_set_client: The character set of the client. The client default character set. When a client sends a request to the server, the request is encoded in that character set.
Character_set_results: Result character Set. When the server returns a result or information to the client, the result is encoded in that character set.
On the client, if Character_set_results is not defined, the Character_set_client character set is used as the default character set. So only the character_set_client character set is required.
Character_set_connection
The character set used for literals and does not has a character set introducer and for number-to-string conversion.
MySQL Character set conversion process:
SET NAMES ' charset_name ' [COLLATE ' collation_name ']:
Add: mysql_query ("SET NAMES UTF8") in the PHP code;
Reference documents:
Http://www.laruence.com/2008/01/05/12.html
Http://dev.mysql.com/doc/refman/5.5/en/charset.html
Http://jingyan.baidu.com/article/48a42057c069d7a9242504fb.html
http://m.blog.csdn.net/blog/zexin1000/7956935
Xampp Mysql garbled