I was planning to switch the host of a website, but I didn't expect to encounter the problem of garbled Chinese characters in Php and Mysql.
The Mysql used by the foreign host in the past 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. Importing data Finally, when I read it with Php, it was full of 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'");