PHP again encountered garbled characters when inserting Chinese characters and displaying MYSQL.

Source: Internet
Author: User
Once again, PHP fixed these programs before inserting Chinese characters into MYSQL and displaying garbled characters. after deleting the database today, I sorted out the program, inserted Chinese characters into the database, and began to see garbled characters again. 1. my & lt; FORM & gt; page defines the page encoding in the HTML content: HTMLcode & lt; metahttp-equiv = & quot; content-T encountered PHP again and encountered garbled characters when inserting Chinese characters and displaying MYSQL.
These programs have been completed before. after deleting the database today, sort out the program, insert Chinese characters to the database, and then garbled characters will appear again.

1. my Page, define the page encoding in the HTML content:
HTML code
   
   


2. when mysql creates a database and a table, it defines the encoding:
PHP code
   $ Sqlb = "create table test (.....) ENGINE = InnoDB default charset = utf8 AUTO_INCREMENT = 10; "; [B] 3. when connecting to the database, define the encoding: [/B] [code = PHP] $ conn = mysql_connect ($ host, $ user, $ pwd); mysql_query ("SET character_set_connection = UTF-8, character_set_results = UTF-8, character_set_client = binary ", $ conn );


...
The above has ensured that the database, page, and even Database connection are all unified encoding: UTF-8 format.

But why is garbled characters still displayed when inserting Chinese characters into the database?

------ Solution --------------------
PHP code
$ Conn = mysql_connect ($ host, $ user, $ pwd); mysql_query ("SET character_set_connection = UTF-8, // here UTF-8 is rewritten to utf8 character_set_results = UTF-8, // same as character_set_client = binary ", $ conn );
------ Solution --------------------
Discussion

Reference:

PHP code
$ Conn = mysql_connect ($ host, $ user, $ pwd );
Mysql_query ("SET
Character_set_connection = UTF-8, // here UTF-8 is rewritten to utf8
Character_set_results = UTF-8, // same as above
Character_set_client = binary ", $ .........

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.