Ham
Ham

Reputation: 814

Mysql display chinese characters

I have been using php + mysql (phpmyadmin) to construct websites with Chinese contents (utf-8) for a long time.

When inputting forms, and also generate output php from db, the Chinese Words display well; but when I look at the database, although sometimes they are normal chinese characters, but something they are not (become strange strings), that made me notice that, the way that mysql handle and input data is not always utf-8.

Some experts on web mentioned, mysql were used to record the input data by latin1; nevertheless, I note that the existing charset in phpmyadmin is utf-8...

Will there be any solid way to detect the encoding format of chinese characters appeared in a phpmyadmin table cell?

Also, apart from mentioning at header of the page, will there be any method so that I can make sure the data entered to the db is utf-8 but not others?

Thank you.

Upvotes: 2

Views: 8154

Answers (2)

zac1987
zac1987

Reputation: 2777

in my case, it just because htmlentities(); Solution is change echo htmlentities($email_db); to echo htmlentities($email_db, ENT_COMPAT, 'UTF-8');

Upvotes: 0

deceze
deceze

Reputation: 522510

The biggest problem that people encounter in this regard is that they don't tell MySQL that they're sending/expecting UTF-8 encoded data when connecting to the database, so MySQL thinks it's supposed to handle latin1 encoded data and converts it accordingly. Issue the command SET NAMES utf8 after connecting to the db or use mysql_set_charset.

Upvotes: 5

Related Questions