take me home country roads PHP+MYSQL solution to garbled characters

WBOY
Release: 2016-07-29 08:38:33
Original
1144 people have browsed it

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 I had to check the information and found a solution, which is to add SET NAMES UTF8 after mysql_connect to eliminate garbled characters in the UTF8 database. For GBK database, use SET NAMES GBK. The code is as follows:
$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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!