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 ", $ .........