A quick solution for PHP to read MYSQL Chinese garbled characters

Source: Internet
Author: User
The following small series will provide you with a quick solution to read MYSQL Chinese garbled characters in PHP. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the host of a website. I didn't 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:

$ Mysql_mylink = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_pass); mysql_query ("set names 'gbk '");

The above is all the content of the quick solution for PHP to read MYSQL Chinese garbled characters. I hope it will be helpful to you and support PHP Chinese network a lot ~

For more articles about how PHP can quickly read MYSQL Chinese garbled characters, refer to PHP Chinese network!

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.