01 January 2013

MySQL does not display Chinese

NOTE: Generally, 3 places - (1)  When creating a database, you should include character set; (2) In head section of html code of a web page, you should define character set; (3) after mysql_select_db, you should include mysql_query("set names gbk;"). That is all.

(1) In the file 'my.ini', add the following two lines:

 [client]
default-character-set=gbk

[mysqld]
character-set-server=gbk

Restarted MySQL server.


(2) When creating a database, use -
create database [database name] character set 'gbk' collate 'gbk_chinese_ci';


(3) Run the command 'show create table ...'.

mysql>show create table [table name];

Check what the default default charset is.

If it is not 'gbk', change it into 'gbk'.

The method is -

create table if not exists  '[table name]' (
...
) engine=InnoDB default charset=gbk;


(4) In the PHP page, after the statement -

mysql_select_db("dbname", $db);

Add the following statement -

mysql_query("set names gbk;");


After the above 3 actions, Chinese will be displayed.

No comments:

Post a Comment