The problem of garbled after PHP connection to MySQL database

Source: Internet
Author: User
This article mainly introduces the content of the PHP connection MySQL database after the garbled problem, has a certain reference value, now share to everyone, the need for friends can refer to

In general, there are two cases of Chinese garbled:

One: PHP code and Database encoding method is inconsistent:

General solution to this problem: Reset the database encoding format:

How to solve the problem: 1. Change the encoding format of the database configuration file to match the encoding format used in your PHP code.

2. After fetching the $conn value, give the returned object (Resource) $conn set the encoding format (for example, character encoding Utf-8): Mysqli_set_charset ($conn, "Utf-8").


Two: PHP code used in the encoding format and the browser decoding the encoding format inconsistent:

Workaround: Set the browser's decoding method in the returned HTTP response message.

Specific ways to solve the problem: 1. Add code at the beginning of the file: header ("Content-type:text/html;charset:utf-8")

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.