UTF-8 dual encoding, but why? PHP / MySQL

I have some forms that insert some data into a MySQL database, and for some reason characters get double utf-8 encoding. You do not see it in the interface of my website, but in the background you do, if I look at the data from phpmyadmin, it is encoded twice.

Also, to display the data entered with phpmyadmin, I need utf8_encodeit.

If I use uft8_decode()for my data before putting it into my database, it will work, but then I will have to use it again utf8_encode()to display my data correctly, and I would like to find a better solution that rewriting most of my code.

The characters I come across are the Danish characters Γ¦, ΓΈ and Γ₯.

I have all the settings that I can find in php.ini for utf-8, everything I can find in phpmyadmin for utf8, the html meta tag set to utf-8, and still I have this error. / p>

So my question is: does anyone know why this is happening, or how can I fix it? ..

Update: After running the mysql code suggested by Jako, the data is properly encoded in the internal interface of the database when it comes from the interface, but do I still need to run utf8_encode()any ideas to display the data correctly on the interface? ..

Update 2: Again, after running the code from the answer to this question , I still had problems, now the encoding was turned off and off utf8, and I suspect phpmyadmin to restore the encoding in some way. I found a new way to do things, and it works flawlessly, as described in my answer below ...

+3
source share
2 answers

Ok, I found the answer! I searched a little more (I did this for several hours) and found this question: Should I use "SETTINGS NAMES"

Using the answer from this question, I executed this query:

mysql_query("SET character_set_client = UTF8");
mysql_query("SET character_set_results = UTF8");
mysql_query("SET character_set_connection = UTF8");
mysql_query("SET names UTF8");

What is it, it works fine now on all my php scripts. Nevertheless, thanks to Yako for being right with me.;) The strike>

: , , , , . mysql_set_charset() script:

mysql_set_charset("UTF8");

, .

+2

, .

mysql_query("SET names UTF8");
+5

All Articles