PHP read MySQL Chinese data garbled solution

Source: Internet
Author: User

The simplest way is to programmatically access MySQL by adding a line of code: mysql_query ("SET NAMES ' GBK '");

1.PHP page language itself is not the appropriate encoding type, when you write directly in the script in Chinese is certainly garbled, needless to say, the database.


Workaround: Select ' UTF8 ' or ' gb2312 ' so that the client browser automatically selects and displays the correct Chinese display. Note: ' UTF8 ' or ' gb2312 ' can be displayed correctly in Chinese.
2. The encoding type in the database MySQL is incorrect.

Workaround: When creating the database, MySQL character set select ' UTF8 ', MySQL connection proofing select Utf8_general_ci, so create the database used to store Chinese certainly no problem, otherwise, your Chinese first in MySQL is garbled, Not to expect it will give you the correct display in the PHP page.


3. It is related to the normal script editing environment.

For example, some of the content is written in Word, some are written in Notepad, some with EditPlus, Ultraplus and other text editor. Sometimes I write Chinese directly in the DW,


Workaround: Try to use the same editor as possible. If it is a copy of the existing content, it is recommended to use the Ultraplus encoding conversion function to convert it to UTF8 or gb2312. It doesn't matter what type it is converted to, it's critical that the code in your PHP Web application be consistent.

PHP read MySQL Chinese data garbled solution

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.