How to read MYSQL Chinese garbled characters in PHP
Source: Internet
Author: User
The solution for PHP reading MYSQL Chinese garbled characters is to switch the host of a website. I did not expect Php and Mysql Chinese garbled characters.
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:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service