Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL collation

I faced a very strange problem when developing on PHP and MySQL. I had such problem 4-5 years ago, but since than not. And really don't remember how I solved it.

Well... the problem: I'm having database with collation of utf_unicode_ci, but when inserting georgian letters: სახელი და გვარი in the database I'm having მიხეირ<- this symbols. What could the problem be? and how to solve it?

Any ideas?

like image 571
mrGott Avatar asked Mar 04 '26 09:03

mrGott


1 Answers

According to Eray's answer I realized that utf8_general_ci shuld be set in collation and not utf8_unicode_ci

and in addition to that use mysql_set_charset('utf8', $connection) function.

Here's the sample:

        $connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
    mysql_set_charset('utf8',$connection);      
    if (!$connection) {
        die("Database connection failed: " . mysql_error());
    } else {
        $db_select = mysql_select_db(DB_NAME, $connection);
        if (!$db_select) {
            die("Database selection failed: " . mysql_error());
        }
    }
}

So having mysql_set_charset on the second line solved my issue.

Hope it helps anyone..

like image 181
mrGott Avatar answered Mar 06 '26 00:03

mrGott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!