开发者

Why can I not view foreign language characters in my mysql DB?

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();


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜