Question

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();
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top