Summary of PHP solutions for reading MySQL Chinese garbled characters

Source: Internet
Author: User
Tags php and mysql

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:

 
 
  1. $ Mysql _ mylink = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_pass );
  2. 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.

Related Article

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.