Skip to main content
Inspiring
April 22, 2006
Answered

Japanese from mysql not displaying properly

  • April 22, 2006
  • 2 replies
  • 420 views
I have a static site in Japanese that is working fine in Dreamweaver. I'm trying to add a database connection with php/mysql, but the connection between my page and the database is garbling the text (moji bake) in both directions. I'm using UTF-8, both on the page, and in the database. (I tried with SJIS but that only gave me a different kind of moji bake). I can enter Japanese text directly into the database without any problem, but that text gets garbled when I read it on the page, and the text submitted by the form also gets garbled going into the database.

This seems to be a fairly common problem, looking at other unanswered posts in this forum. Anyone have any ideas?

Thanks,
Daniel Sofer / Hermosawave Internet
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer Daniel Sofer
Hi Michael:
Thanks for the quick reply. That did it.
The trick for me was how to get the mysql command SET NAMES in the php code...

So to summarize for other DW/php users:

1) Add a line after mysql_select_db, but before mysql_query:
mysql_query("SET NAMES 'utf8'");
(it's okay to have more than one mysql_query line)

2) Just before the html tag add:
<?php header('Content-type: text/html; charset=UTF-8'); ?>

Daniel Sofer / Hermosawave Internet

2 replies

Daniel SoferAuthorCorrect answer
Inspiring
April 23, 2006
Hi Michael:
Thanks for the quick reply. That did it.
The trick for me was how to get the mysql command SET NAMES in the php code...

So to summarize for other DW/php users:

1) Add a line after mysql_select_db, but before mysql_query:
mysql_query("SET NAMES 'utf8'");
(it's okay to have more than one mysql_query line)

2) Just before the html tag add:
<?php header('Content-type: text/html; charset=UTF-8'); ?>

Daniel Sofer / Hermosawave Internet

Inspiring
April 22, 2006
.oO(Daniel Sofer)

>I have a static site in Japanese that is working fine in Dreamweaver. I'm
>trying to add a database connection with php/mysql, but the connection between
>my page and the database is garbling the text (moji bake) in both directions.

You also have to define the connection character set, so the data will
be transfered correctly.

10.4. Connection Character Sets and Collations
http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html

I do this by sending a

SET NAMES 'utf8'

to the database right after establishing the connection. Additionally
your server has to send the correct charset parameter to the browser.
In PHP you can achieve this with a header() call:

header('Content-type: text/html; charset=UTF-8');

HTH
Micha