The problem with Chinese is that the code is unified or it will be garbled.
1. Database and PHP page coding Unified
2. Database Data table field and page encoding unification
If you do not have the above two kinds of Chinese garbled problem, then we look at MySQL Chinese garbled problem solving examples
1. My MySQL table is as follows
--
--The structure of the table ' Useradmin '
--
The code is as follows |
|
CREATE TABLE IF not EXISTS ' Userain ' ( ' ID ' int (4) not NULL auto_increment, ' username ' varchar DEFAULT NULL, ' userpass ' varchar DEFAULT NULL, ' Logins ' int (4) not NULL DEFAULT ' 0 ' COMMENT ' landing times ', ' Logintime ' timestamp not NULL DEFAULT current_timestamp on UPDATE current_timestamp, ' Mid ' char (1) not NULL DEFAULT ' 0 ', PRIMARY KEY (' id ') ) Engine=myisam DEFAULT Charset=utf8 auto_increment=7; |
All the above are UTF8 encoded so that I can test a Chinese
The code is as follows |
|
INSERT into ' userain ' (' id ', ' I am Chinese ', ' userpass ', ' logins ', ' logintime ', ' mid ') VALUES (1, ' admin ', ' 7c1f03139281878059b909c42ccf2f6a ', 0, ' 2010-04-14 14:20:26 ', ' 1 '); |
I said I can get into the normal, and some people say no. In fact, the key is not in the SQL statement, the focus is PHP connection to MySQL data encoding settings, as follows.
Page edits as GBK
The code is as follows |
|
<?php Configure MySQL Database connection parameters $db = mysql_connect ("localhost", "User", "password"); mysql_select_db ("message", $db); Add the following line before executing the SQL statement ?> |
After the connection to the database submitted must be garbled or saved not carried out, if you want to solve this MySQL Chinese garbled problem is very simple in the query
The code is as follows |
|
<?php Configure MySQL Database connection parameters $db = mysql_connect (www.45it.net, "User", "password"); mysql_select_db ("message", $db); Add the following line before executing the SQL statement mysql_query ("SET NAMES ' UTF8 '", $db); |
Then you will find that even if your page is GBK, the data saved will be successful.
PS: For Ajax we must use UFT8, because Ajax only supports UFT8 mode transfer data.