National characters corrupted in db (not utf8?)

Hi,

I have a problem with Polish characters. They are completely incorrect in the database.

I think I have set everything to utf-8 but I won't give my arm.

Other scripts (drupal etc) don't have this problem on my machine.

Do know how to sove this?

Regards,

Greg

  • Hi greg606 :)  I had a similar problem with Hebrew characters.  Apparently it was something to do with the set up of the database on my hosted account.  I contacted my server support and they told me to add this line in engine/lib/database.php

    mysql_query("SET NAMES utf8");

    I don't know if that will solve your problem but if you are on a hosted server, I would definitely suggest contacting support.

    Here's the code with the surrounding bits too:

    // Connect to database
                    if (!$dblink[$dblinkname] = mysql_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, true))
                        throw new DatabaseException(sprintf(elgg_echo('DatabaseException:WrongCredentials'), $CONFIG->dbuser, $CONFIG->dbhost, $CONFIG->debug ? $CONFIG->dbpass : "****"));
    ##add the line below
    mysql_query("SET NAMES utf8");               

    if (!mysql_select_db($CONFIG->dbname, $dblink[$dblinkname]))
                        throw new DatabaseException(sprintf(elgg_echo('DatabaseException:NoConnect'), $CONFIG->dbname));
               
                // Set up cache

     

     

     

     

  • Susan! you're saving my ... great! :)

    Why should I contact support? ;) Your directions, are more than enough...

    Anyway, I think that our great elgg developers should cater for the needs of non-english speakers, shouldn't they?

  • UTF-8 always seems to be a problem with PHP + MySQL applications.  I'll investigate this solution to see if it's something we can use generically, or if there's a better solution around.

    Just a quick note that if you do find problems (and solutions!) like this, please put them in trac at http://trac.elgg.org/elgg.  The core developers get emails from trac, so it's a good way to let us know!

  • Thanks, Brett

    Susan, will you put the problem and your solution there?

  • I've already put it in trac so I won't forget. ;)

    It's at https://trac.elgg.org/elgg/ticket/1181

  • I have a similar problem, but i couldn't solve with: mysql_query("SET NAMES utf8").

    The problem: Some users in elgg when they save their profile with spanish/brazilian special characters like áéíóú. They appear corrupt when de page is viewed.

    The test: The data was saved wrong in the DB like iso, not uft8 data. And I could reproduce it changing the page codification to iso-8859-1 and saving the profile. 

    The solution: Force saving always in utf8. How. ¿?. I search but i couldn't find a solution.

  • To save input from the site in utf-8

    You should use charset as utf-8.

    Make this entry in metadata in header.

     

     

  • The default Elgg theme already has:

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

    in the page_elements/header view.

  • Preface

    Elgg "vanilla" core don't ready for 8-or more bit charsets. It was true for 1.5, it is true for 1.6.*

    Patches, which was usable for Elgg RE (Russian) v 1.5 (not tested yet in 1.6)

    1. engine\lib\database.php, added to the very bottom

    mysql_query ("set names utf8");
    mysql_query ("set character_set_client='utf8'");
    mysql_query ("set character_set_results='utf8'");
    mysql_query ("set collation_connection='utf8_general_ci'");

    (database was created before with UTF8, collation order - utf8_general_ci)

    2. views\default\page_elements\header.php, on top has now

    <head>
       <meta http-equiv="charset" content="utf-8" />
       <meta http-equiv="Content-type" content="text/html;charset=utf-8" />

    3. Embed mod: embed.php + upload.php

    <?php
    header("Content-type: text/html; charset=utf8");

    4. Messageboard mod: /mod/messageboard/ajax_endpoint/load.php

    <?php
    header("Content-type: text/html; charset=utf8");

    5. Riverdashboard mod: /mod/riverdashboard/index.php

    <?php
    header("Content-type: text/html; charset=utf8");

    At least it eliminates most of problems für reine 8bit-sprachen in den Lokalisationen UTF8

    2greg606: You can't use chars beside US-ASCII for usernames without huge rewriting of code - all letters from usernames are used for building path to profile-related files (avatars, maybe smth. more)