+2  A: 

You appear to be trying to store HTML-encoded strings in your database. Don't do that, it will only break your ability to do string operations like searching reliably. You should be able to store raw UTF-8 encoded characters as bytes in your database.

You don't say what environment you're using to read the database or how you get the ‘incorrect’ string at the bottom (which is UTF-8 bytes read using ISO-8859-1 encoding). If they appear in your web page (and you're specifying UTF-8 in the headers and/or <meta> tag), you're presumably pretty much there.

bobince
A: 

@ bobince I didn't understand you... what do you mean by HTML-encoded? You mean that way the data is now stored to database is ok? I use utf-8 encoding (set in the head of html document). Symbols show as they are suppose to, but I've just discovered problem... it's related with this topic When I store (manually, for now) utf-8 entities of characters in database then there is no problem...

ile
please add comments as comments not as answers.
Sorin Sbarnea
+2  A: 

Setting the MySQL table charset is not enough - you should also take care to set the correct charset for the client, the connection and the results, which defaults may differ from server to server making your database less than portable: the same database content might be displayed differently moving to another server.

I've been storing slovenian text into MySQL for some time now and this is what works for me:

  • the first thing you do after connecting should be to issue a "SET NAMES utf8" query
  • make sure that the strings you're storing are utf-8 to start with: if you're taking them from a web page form make sure the page is UTF-8
  • be careful what tools do you use to browse/edit the database contents online: PhpMysqlAdmin is definitely unsafe.

Hope this helps.

djn
Could you please be more precise. I don't know WHERE exactly should I put this query? Do I put it in each query to database? I see that SET NAMES utf8 is replacement for 3 variables (character_set_client, character_set_results, character_set_connection) but I am not clear with where to put this query. Thank you for help!
ile
Just make it the first query to the database - right after you domysql_connect($server, $user, $password);
djn
Oops, must have pushed the wrong button. What I was trying to write was:mysql_connect($server, $user, $password);mysql_select_db($dbname);mysql_query("SET NAMES utf8"); //the very first query...Doing this will allow your connections to be server/client-independent. Since I started doing it this way I can safely move databases from my Windows devel server to my Linux production box via the MySQl Migration Toolkit or copying straight db-to-db with HeidiSQL and a SSH tunnel - all witout any charset mismatch.
djn
Take note: you have to start doing SET NAMES before you send anything to the database. It won't 'repair' what is already stored there.
djn