WordPress.org

Ready to get started?Download WordPress

Forums

newbie: mysql and utf-8 (11 posts)

  1. cooldown
    Member
    Posted 8 years ago #

    I am new to wordpress, mysql, php, etc., so sorry for not so clever question.

    As many others, I have a problem with some Eastern Europan characters in my backup copy - they don't show up correctly. I have read about the problem in many forums. One piece of advice was to use a query
    <?php
    mysql_query("SET NAMES 'utf8'", $conn);
    ?>"

    The problem is that I don't know where to put this query: which file, where exactly ,etc.? could anyone help me out?

    Thank you

  2. moshu
    Member
    Posted 8 years ago #

  3. cooldown
    Member
    Posted 8 years ago #

    thanks for the link

    unfortunately, this didn't help
    <?php
    mysql_query("SET NAMES 'utf8'", $conn);
    ?>"
    it got worse, now ALL nonstandard characters became smth like Ä…Ä?ęėįšųūž

    maybe my provider's mysql server is set incorrectly, i don't know :(

  4. moshu
    Member
    Posted 8 years ago #

    OK, let's go back to the basics.
    Before the backup what was your character set (encoding)? Utf-8?
    What is the setting now?

    The only other "fix" I've found is this:
    http://wordpress.org/support/topic/55282?replies=10#post-303707
    a bit different from the previous one.

    What Eastern European language?

  5. cooldown
    Member
    Posted 8 years ago #

    thank you moshu for your attention, i got little bit nervous because of all this problem, so i had to eat a cake to calm down :)

    at least i got to the initial problem, at first I made a mistake and put in wp-db after line 43
    mysql_query("SET NAMES 'utf8'");
    so everything got messed up but then I put
    mysql_query("SET NAMES 'utf8'", $conn);
    and at least everything went back to normal EXCEPT TWO LETTERS. But I had the same situation before putting SET NAMES, so it didn't help.

    OK I'll try to explain but I have to say that this is not the problem in WordPress only, this is smth related to mysql encodings... I have the same problem with my Phorum program.

    I use UTF-8 everywhere in WordPress and I write it in the Lithuanian language: http://mokslas.ktv.lt/
    I didn't notice anything wrong when writing posts, all the letters show up correctly, by the way, beside Latin letters Lithuanian has additional letters: ą?ęėįšųūž
    Problems arise when I try to restore posts, etc. from a backup copy and problems only with TWO letters "?" and capital "Š" - you cannot restore them; strange characters show up instead of them when restoring from a backup. You can see this in the first experimental post: http://mokslas.ktv.lt/

    I have read in forums that this happens with some characters, a bug in mysql or something. But all the guys say that SET NAMES in php code helps; in my case it made no difference though I tried to back through WordPress and through phpMyAdmin.

    Maybe there smth wrong when i open .sql backup file in editors like notepad but this is hardly a problem because only two letters are affected. Or maybe
    mysql_query("SET NAMES 'utf8'", $conn);
    should be put in some other places in other files
    or maybe some other queries should be made
    I don't know.

  6. moshu
    Member
    Posted 8 years ago #

    OK. What you could try - because I see you are using WP 2.0.
    Try to delete/empty the folder called cache under wp-content (wp-content/cache)
    Maybe we are seeing an earlier cached version of the site.

    It is definitely a MySQL bug and the line
    mysql_query("SET NAMES 'utf8'");
    seemed to help others.
    (Even when this forum was moved at the end of last year, all the special characters in older posts are screwed up...)

    Try that cache thing.

  7. cooldown
    Member
    Posted 8 years ago #

    emptying cache didn't help,
    well maybe i will find a solution one day :)
    thanks

  8. Chionsas
    Member
    Posted 8 years ago #

    It helped me to put:
    $this->query('SET NAMES UTF8');
    in wp-db.php line 57 (just before the "$this->select($dbname);").

    It's a new site, though, so I'm not fully aware of the problems that could arise with the already-in-db texts.

    I'm a Lithuanian too, btw! =)

  9. condi4prez
    Member
    Posted 8 years ago #

    When I placed the

    $this->query('SET NAMES UTF8');

    line in wp-db.php, as above, all I got back was a database error, "no system variable NAMES"

  10. Seisuke Kuraishi (tenpura)
    Member
    Posted 8 years ago #

    condi4prez,

    If you want UTF-8 support, you must use MySQL4.1 or later. The "SET NAMES" statement works as well with these versions.

  11. condi4prez
    Member
    Posted 8 years ago #

    So close, our server has MySQL 4.0.26

Topic Closed

This topic has been closed to new replies.

About this Topic