views:

27

answers:

2

I need a bit of help understanding how utf8 data is supposed to look when stored inside the database.

I'm using mysql and php, the database is set to utf8, the collation on the column "p_name" is set to "utf8_unicode_ci".

When I insert the data I pass it through this function

function convert_charset($in_str) 
    { 
      $cur_encoding = mb_detect_encoding($in_str) ; 
      if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8")) 
        return $in_str; 
      else 
        return utf8_encode($in_str); 
    }

then insert it into the database. When I read out the data in php and display it in the browser i am using utf8 in the page, and the data displays right, however I'm suspecting something might be wrong.

Take the FRENCH word éditez that's how it's supposed to look. However inside my database when I look at it the same word is being stored as éditez. Is this right? Is this how mysql is supposed to store that word, or have I got something set wrong?

Here's what I have set already:

  1. php.ini --> set to utf8
  2. database --> set to utf8
  3. table column --> set to utf8_unicode_ci
  4. html pages --> set to utf8.
+2  A: 

try this query right after your database connection setup functions

mysql_query('SET NAMES "utf8"');

antpaw
Great This did it. Thanks a bunch!
Ronedog
A: 

Have you tried setting your connectionstring to UTF8 as well?

Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; CharSet=UTF8;
SchlaWiener