The thing with the euro sign

Published on and tagged with ant  cakephp  jdbc  mysql  problem  tip

Yesterday, Kabuto asked in the IRC whether someone is using UTF-8 for the MySQL databases and if they experienced some problems with the euro sign. Yes, I use UTF-8 and I also store the euro sign in my database, and I assumed it works for me. But that was an illusion, the euro sign was shown as a question mark as I did a query. A sign of an encoding problem…

Since it worked when I entered the euro sign in my application, the problem had to be in my sql scripts or in my ant script I use to execute the sql scripts. The sql scripts were ok, as they worked when executed via MySQL Query Browser. So the problem had to be in my ant script. But what was the cause of the problem? After searching for a long time I found the problem: I have to specify the encoding in the URL used by JDBC. Instead of

jdbc:mysql://localhost/mydb

I have to use

jdbc:mysql://localhost/mydb?characterEncoding=UTF-8

Oh, I really love this entire encoding stuff ;-)

9 comments baked

  • RosSoft

    Working with CakePHP and UTF8, I have a problem with encoding. With this SQL sentence I resolved it:

    SET NAMES ‘utf8’;

  • elliot

    Hey thanks – i’ve been in charset hell for some time trying to support a multilingual site.. i first tried latin1_bin til i realised it made searches case sensitive, so i tried latin1_general_ci and ended up with a problem with the € symbol, then i moved to utf-8 and STILL had this problem. Thanks to a quick google i came accross your blog and this sorted it. Hopefully my character set headaches will soon be long gone!

  • cakebaker

    @elliot: I am glad to hear that this post was useful for you!

  • Richard van den Tol

    It took me many hours to get €-sign (Euro) displayed in AJAX application. Solution: Start PHP program with next line:
    header(“Content-Type:text/html; charset=iso-8859-1”);

  • cakebaker

    @Richard: Thanks for this hint!

  • Gustav

    Haha, you’re lucky that’s the only char that’s not in your charset :-)
    I’m from Sweden and need to fix this for every app I’m working with…

    The Swedish chars that fuck things up: åäöÅÄÖ

  • cakebaker

    @Gustav: In German we have similar special chars: äöüÄÖÜ, but fortunately most apps are in English ;-)

  • B_Patient

    Thanks Richard!

    You comment was so useful, it tooks me 2 hours to find what is wrong in my codes.

    Thanks again

  • B_Patient

    Hey Guys, check well this code does not work in IE, i checked using IE6 and i found a link on google saying that charset=iso-8859-1 does not work with IE 9.

    Any improvemt Richard?? Let us know if you find how to fix it

Bake a comment




(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License