Jump to content

UTF8 lithuanian characters unrecognized in MySQL database


Baltas
Go to solution Solved by Baltas,

Recommended Posts

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.

 

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: http://akrabat.com/php/utf8-php-and-mysql/

Then I tried to set Apache's AddDefaultCharset in .htaccess file using this link here: http://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.

 

 

Link to comment
Share on other sites

What would happen if you try to insert lithuanian characters without filling the html form?

<?php

$conn = mysql_connect('host','user','password');

$db_name = mysql_select_db('wp-database', $conn); 

mysql_set_charset('utf8', $conn); 

$query = "INSERT reg_form (title,body) value ('Aciu. Ačiū', 'Sveiki atvyke Sveiki atvykę')";

$res = mysql_query($query); 
Link to comment
Share on other sites

Jazzman1, NOW I reinstalled (freshly) wordpress, created database using

CREATE DATABASE db_name
 CHARACTER SET utf8
 DEFAULT CHARACTER SET utf8
 COLLATE utf8_general_ci
 DEFAULT COLLATE utf8_general_ci ;

 

Then, I created table using this:

CREATE TABLE reg_form(
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` char(50) NOT NULL,
PRIMARY KEY (`id`) )
 DEFAULT CHARACTER SET utf8   
 COLLATE utf8_general_ci;

 

Then I tried to fill the form field. Those strange hieroglyphic were saved. Then I tried your suggested method - to pass value straight from the code. STILL the same shit! : /

 

Link to comment
Share on other sites

  • Solution

HOLLY S**T!! 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? : ))

Edited by fenway
profanity
Link to comment
Share on other sites

thanks everybody for trying to help me : )

 

I'm still waiting for detailed explanation : )

 

Cheers

 

When you are using mysqli_set_charset() the first argument must be the link identifier unlike from mysql_set_charset().

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.