The following articles mainly introduce the actual solution for PHP to read MySQL Chinese garbled characters. When switching the host of a website, Php and MySQL Chinese garbled characters are usually encountered, the following is a description of the specific solution. I hope it will help you in your future study.
In the past, MySQL for foreign hosts was 4. x series, I feel better, no matter GBK and UTF-8 are not garbled, did not expect the new host MySQL is 5.0 version, after importing data, read out with Php is question mark, garbled text. I remember that I had a previous experience with Garbled text during Switching. The reason must be the difference between MySQL versions.
I had to check the information and found a solution. I added a set names UTF8 sentence after MySQL_connect to eliminate garbled characters in the UTF8 database. For GBK databases, I used 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 content is a description of the solution for PHP to read MySQL Chinese garbled characters. I hope it will help you in this regard.
In the future, we will introduce more knowledge about how to solve Chinese garbled characters in MySQL for PHP reading. I hope you will review our articles frequently.