Home > Article > Backend Development > A quick solution to read Chinese garbled characters in MYSQL using PHP
I was planning to switch the host of a certain website, but I didn’t expect to encounter the problem of garbled Chinese characters in Php and Mysql.
The Mysql used by the previous foreign host was the 4.x series. It felt relatively good. There was no garbled code in both GBK and UTF-8. I didn’t expect that the Mysql of the new host was version 5.0. After importing the data, I used Php The words read out are all question marks and garbled characters. I remember that I once had the experience of garbled characters when switching. The reason must be the difference between Mysql versions.
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 above is the entire content of the quick solution for reading MYSQL Chinese garbled characters in PHP brought to you by the editor. I hope it will be helpful to everyone. Please support the PHP Chinese website~
More quick solutions to reading MYSQL Chinese garbled characters with PHP For related articles, please pay attention to the PHP Chinese website!