views:

160

answers:

1

I am inserting the following characters into my DB: 汉字 / 漢字

This is the meta tag on the page that is inserting the characters:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

I have altered all the columns in my table that is holding the characters to be utf8_unicode_ci

The foreign characters show up like so in the DB: 汉字 / 漢字

When I use a sql statement to display those foreign characters on a page, they display correctly again as: 汉字 / 漢字

I am guessing I have some setting that is not correct in my DB, since it stores it correctly, but does not display it correctly.

What can i do to make the foreign language characters to display correctly in my DB?

EDIT: Here is my insert:

$sql = 'INSERT INTO orders (foreign_characters)
        VALUES (?)';

$stmt = $conn->stmt_init();
$stmt->bind_param('s', $_SESSION['foreign_characters']);
$inserted = $stmt->execute();
+3  A: 

Is the connection to the database also UTF-8 encoded?

Give this a try: right after connecting to the mysql database, run the following query.

SET NAMES utf8;

This should do the trick (see MySQL doc). (Yeah, you have to do this everytime you connect.)

BTW: don't just rely on the <meta>-Tag, send the appropriate HTTP header.

middus
thanks, but I am a bit confused. Where do I put that query? Within the same query that is inserting the foreign characters into the DB? Also, what is the appropriate header I should be sending and how should I write that?
zeckdude
I added my insert query so you can see what I am doing, as I am not sure where to add the query you suggested.
zeckdude
Do i add the query you suggested as a separate query or part of the insert query I am already running?
zeckdude
Great! It worked wonderfully! I added $conn->query('SET NAMES utf8'); Thanks again!
zeckdude
Sorry, I did not see your message on time. You did the right thing: a new, seperate query right after you established the connection.
middus