Well, I’m going to ask you a question because from William Nascimento’s answer I found the answer.
The problem is not a COLLATE problem but a problem between Mysql and PHP. We know that PHP does not use utf8. It was intended for PHP6 but will 'theoretically" happen only in PHP7.
Let’s then see how to make a site in utf8 to understand the difficulty.
At the beginning, I will create my BDD and then the tables. Everything in utf8. When I will test, using the Guilherme Nascimento test, it is all right. Legal!
Then I will create my PHP code and create the HTML page where I will put:
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
Then I will create a php document, where I will put for example:
define ("TITULO","Direção");
I will save in UTF8 and send using FTP software, which will not change the code.
I will create a page with a form and an INPUT field using the title defined in my define.
Cool! I will see "Direction" as title, I will type for example "national direction" in the field. In Submit, the content will be sent in the second PHP page and I will save using a SELECT.
When reading, I will simply do a SELECT * FROM TAB. I will do an echo by adding the title and then the contents of my table and I will have:
Direção: direção nacional
Right now, I’m going to make sure it’s all right. But it’s not. Actually, within the table, I don’t have "national direction". I have "National Right". But as in reading, it has automatic data conversion, it gives the illusion that the data is correct. The problem is that when I will need to do an ORDER BY, Mysql will do using "dire the national" and the result will be wrong.
In his example Guilherme Nascimento uses a fiddle then, a closed system. Which explains that works perfectly.
Hiccup
The solution is simple. Immediately after mysqli_connect, you need to put mysqli_set_charset.
$handle = mysqli_connect($sql_host,$sql_user,$sql_password,$sql_database);
mysqli_set_charset($handle,'utf8');
From this, when you will type "direction", the table will have "direction" and the ORDER BY will be bandstand.
But for the old data???
Unfortunately, exporting to re-import will change nothing. Because I will export "dire o nacional" and reimport "dire o nacional". Actually, you need to read the data WITHOUT doing mysqli_set_charset, then do mysqli_set_charset and do an INSERT.
So:
1 - Conectar usando mysqli_connect (sem fazer o mysqli_set_charset)
2 - Ler os dados da tabela e salvar para preparar o query para INSERT elas
3 - Fazer um TRUNCATE na tabela
4 - Fazer o mysqli_set_charset($handle,'utf8');
5 - Fazer o INSERT dos dados
So I’m going to read the "old" way and then I’m going to read the "new" way.
Now it’s all right!!
I think that <a href="http://imasters.com.br/artigo/1203/postgresql/sort-of-accented/">Link</a> meets your needs
– GabrielBicca