Categories

Blog Archive

Live Traffic Feed

In: ,

Retrieving Japanese Text from MySQL using PHP

Our client's website is a multi-language website including Japanese and English.
It was working well until I was asked to develop a simple database ap for the site.
I have run into this problem.

When I try to retrieve the data from MySql using PHP. The data become "??????".(Question Marks)
* The data inside have Japanese and English. 
  So my db and table is defined as CHARSET=utf8 COLLATE=utf8_unicode_ci
* It display in the mySQL administration tools without any problem.
* It display normally in phpMyAdmin(web browser) too.
I know many developers also have run into this problem, so here's the block of code that did the trick for me.
Put this  after the database connection.
mysql_query("SET NAMES 'utf8'")

4 comments:

Digiskull said...

thx very much,
very helpful article

Digipure said...

Thank you!

Carmencito said...

thanks. this article helps my current japanese website project

Julien LEMALE said...

I used it too.. But my imode website has a big problem.. the emoji disappear when i used this command..
But I don't understand because..
the emoji are in the html code not in my db.. So..??