Home >Backend Development >PHP Tutorial >take me home country roads PHP+MYSQL solution to garbled characters
The problem of garbled characters in JSP must have been solved, but there are still some people who have not solved the problem of garbled characters in MYSQL, including myself, so I looked for some more information, hoping that this time I can completely solve the problem of garbled characters in MYSQL database.
The first method, a very insightful summary:
Virtual hosts are often changed, and the MYSQL versions of each service provider are different. When the data is imported, there will always be problems such as garbled characters that cannot be displayed normally. After checking a lot of information, I concluded that I Some tips:
The import under WINDOWS should be like this
Use the MYSQL command
Enter the bin directory of mysql under the DOS command, enter mysql -uroot -p password database name
$mysql_mylink = mysql_connect($ mysql_host, $mysql_user, $mysql_pass);
mysql_query("SET NAMES 'GBK'");
The database character set is utf-8
Use this for the connection statement
mysql_query("SET NAMES 'UTF8'");
mysql_query(" SET CHARACTER SET UTF8");
mysql_query("SET CHARACTER_SET_RESULTS=UTF8'");
Another method is that if you have your own machine, you can change the MYSQL character set, which is generally valid in the two versions of MYSQ4 and MYSQL5
Second method: Very good explanation, you can try it
Summary of mysql garbled code processing:
(1) Chinese characters are processed normally in java, and garbled characters are displayed in cmd client because of the character set problem.
(2) Field length setting It is long enough, but when inserting Chinese characters, it prompts com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column. The error is a character set problem.
(3) The garbled code problem is ultimately a character set problem, so start with the characters The set setting considerations are nothing more than the following aspects: server, client, database, connection, results.
----------------------Solution Method----------------------
(1) Modify my.ini (MySQL Server Instance Configuration file)
The above introduces the solution to the garbled code in take me home country roads PHP+MYSQL, including the content of take me home country roads. I hope it will be helpful to friends who are interested in PHP tutorials.