UTF8 lithuanian characters unrecognized in MySQL database

I have well known but quite difficult to sort out problem here. And yes I was searching on forum but those threads are old enough so I decided to create new post.
So I built a website using WP and included html FORM in one page. When user fills the form (in his/her language) the values of the fields’ go into MySQL database table reg_form.

Everything works, the values are saved, BUT some characters (specific in that language) are not recognized. I tried a lot of different methods to solve this, but nothing can help.

Read More

The strangest thing is that if you look at WordPress tables you can find those specific characters are recognizable but not in reg_form table which I created.

I was trying to solve this problem and finally I decided to approach in somehow ridiculous way. I created NEW database, new tables, installed new wordpress, created new form etc.

That‘s what I was doing:

I used this suggestion first:
http://tympanus.net/codrops/2009/08/31/solving-php-mysql-utf-8-issues/

Yes, my files are saved using UTF8 encoding (without BOM). Yes, meta tags are ok. Yes, the FORM uses accept-charset=’UTF-8′. Yes, all tables in database use UTF8. Yes, server, database and tables collation is the same “utf8_general_ci”.

Then I tried to insert in my code this:

$conn = mysql_connect($server, $username, $password);

mysql_set_charset("UTF8", $conn);

Then I tried this suggestion
link here: akrabat.com/php/utf8-php-and-mysql/

Then I tried to set Apache’s AddDefaultCharset in .htaccess file using this link here: httpd.apache.org/docs/2.0/mod/core.html#AddDefaultCharset

BUT… still the problem remains. I can’t see those specific characters properly – only weird hieroglyphic.

Related posts

Leave a Reply

2 comments

  1. The problem you face has to do with a little specific detail in database character encoding settings and WordPress.

    While WordPress has a general character encoding setting that normally takes care about database tables as well, it does not care about the default character encoding setting of the database those tables are in.

    So when your plugin/code adds a database table your own, you need to take care about the encoding settings as well – because by default they will be the database default you create the table in, which most likely is latin-1 which does not work well for your language.

    To set the default character set for the database (replace “wpdb” with your database name if it varies):

    ALTER DATABASE wpdb CHARACTER SET utf8 COLLATE utf8_general_ci;
    

    To change the character set for your existing table *”reg_form”*:

    ALTER TABLE reg_form CONVERT TO CHARACTER SET charset_name;
    

    Note: Backup your database first.

  2. HOLLY SHIT!! FINALLY! : ))))))))

    The problem was that I was using mysqli_ queries. Now I tried to change to mysql_ (notice the change!) queries and it worked!! Two weeks of haaaaard working and researches… Phew!

    Now who can explain me properly the reasons of this phenomena? : ))