Php+mysql storage Data Common Chinese garbled problem summary _php skill

Source: Internet
Author: User
Tags mysql in php code

This article summarizes the common Chinese garbled problem in php+mysql storage data. Share to everyone for your reference, specific as follows:

Php+mysql The common reasons for Chinese garbled:

1. mysql database encoding is UTF8, and PHP page encoding format inconsistent, will cause MySQL in Chinese garbled.

2. Using MySQL to create a table, or select a field when the type set is not UTF8, and the page encoding is not UTF8, may also cause MySQL Chinese garbled.

3. The character set of the PHP page is inconsistent with the encoding of the database.

4. PHP connection MySQL database, operation is set the statement specified encoding and page encoding, PHP page encoding inconsistent.

5. User submitted HTML page encoding, and display data of the page coding inconsistent, will certainly cause the PHP page garbled.

Ways to solve Chinese garbled problems:

1. Web page encoding settings. Generally add properties to file headers

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "> 

Guarantee that the webpage is "utf-8" encoded.

2. PHP code settings. Add the following code at the beginning of the PHP code:

Header ("Content-type:text/html;charset=utf-8");

The file encoding required to be saved is utf-8 (you can open the setting with EditPlus, as shown below), which ensures that the file is also utf-8 encoded.

3. The portion of the table in the database that stores Chinese in the field, to be set to the Utf8_general_ci type.

4.PHP when connecting to a database operation, the field type to set up the operation is UTF8, set the method as follows:

mysql_connect (' localhost ', ' user ', ' password ');
mysql_select_db (' db ');
mysql_query ("Set names UTF8"); * * Set the character set * * *
mysql_query (SQL statement to execute);

I hope this article will help you with the PHP program design.

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.