views:

421

answers:

6

I have reworked a website and now it is xhtml valid etc and using UTF8. Everything is fine, but if anywhere in the Database is a Euro-char it is just displayed as a questionmark.

What would be the right way to fix this? As output is done by Typo3 i cant change much about that.

+5  A: 

Try executing these queries before the queries that fetch data:

SET NAMES utf8
SET CHARACTER SET utf8
karim79
If you're using the php/mysql extension (mysql_connect, mysql_query, ...) and PHP 5 >= 5.2.3 better use mysql_set_charset(), otherwise mysql_real_escape_string() doesn't "know" about the change of the encoding. see http://php.net/mysql_set_charset
VolkerK
+4  A: 

This might be due to wrong database connection encoding

Lookup SET NAMES sql statement

    $db_link = mysql_connect($host,$user,$passwd);
    mysql_query("SET CHARACTER SET 'utf8';", $db_link);
    mysql_query("SET NAMES 'utf8';", $db_link);
ymv
A: 
Thomi
A: 

You could try something like

$value = iconv('ISO-8859-1', 'UTF-8//TRANSLIT', $value);

The "ISO-8859-1" part may be different depending on your MySQL table character encoding.

rwired
+1  A: 

DON'T issue both statements!

Don't issue

SET NAMES utf8
SET CHARACTER SET utf8

one after another. It can cause trouble. I already had bad experience with SET CHARACTER SET utf8 right after SET NAMES utf8.

I recommend to issue only SET NAMES ...

MySQL docs has explanations why: http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html

In short: SET NAMES ... sets connection's charset to the same as client ans result charset. while SET CHARACTER NAME... sets different connection's charset and collation.

Please read the doc and decide whichever it better in your case. Or even better make a test.

Max Kosyakov
+2  A: 

What charset (encoding, collation,...) are you using for the database column that contains the € sign?

The problem could be that your data stored in this column ist mixed up because the € sign is a somehow difficult beast when not using UTF-8 character encoding. The problem ist that the € sign is encoded as \xA4 when using ISO-8859-15 and as \x80 when using Windows-1252 (the common Western-European charset on Windows machines). If your data inside the column is not encoded correctly MySQL won't be able to transcode it into UTF-8 correctly - even if you use SET NAMES utf8.

Stefan Gehrig