Php+mysql storage Data Common Chinese garbled problem summary, _php tutorial

Source: Internet
Author: User

Php+mysql storage Data Common Chinese garbled problem summary,


This paper summarizes the common Chinese garbled problem of php+mysql stored data. Share to everyone for your reference, as follows:

Php+mysql common causes of garbled Chinese:

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

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

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

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 page encoding inconsistent, it will certainly cause PHP page garbled.

How to solve the Chinese garbled problem:

1. Page encoding settings. Attributes are typically added to the header of a file in HTML code:

 
  

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

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

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

and required to save the file encoding method is Utf-8 (can be opened with editplus settings, such as), so that the file is also utf-8 encoding.

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

4.PHP When you connect to a database operation, the field type to set the operation is UTF8, 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 is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1136649.html www.bkjia.com true http://www.bkjia.com/PHPjc/1136649.html techarticle php+mysql Storage Data Common Chinese garbled problem summary, this article summarizes the Php+mysql storage data Common Chinese garbled problem. Share to everyone for your reference, as follows: Php+mys ...

  • 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.