1

All danish characters (æøå etc.) are replaced by questionmarks on my page. It's a classic

Everything (host, database, table) is set to utf8_unicode_ci in phpmyadmin

Every column in the table is set to utf8_unicode_ci

My webpage file is made and saved in UTF-8, and has the php header + meta:

header('Content-type: text/html; charset=utf-8');
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Then I run a mysql charset test in php:

var_dump($conn->get_charset());

The result?

["charset"]=> string(6) "latin1" ["collation"]=> string(17) "latin1_swedish_ci".. (trimmed vardump)

Why? And how can I fix this?

mowgli
  • 2,796
  • 3
  • 31
  • 68
  • 1
    obviously you never bothered setting the php->mysql connection to be utf as well. The ENTIRE rendering pipeline has to be the same charset, or connected by appropriate translation logic. php in utf8 and mysql tables/fields being utf8 are useless if the php->mysql connection is something else. – Marc B Jun 23 '14 at 16:06
  • I tried that, and it worked.. but do I really have to set that on/for the page? Shouldn't it be enough to set global charset in phpmyadmin? – mowgli Jun 23 '14 at 16:06
  • no. because phpmyadmin's settings will not affect YOUR code. It's like saying "well, my friend's car has a fancy stereo. why doesn't my car have a fancy stereo?" – Marc B Jun 23 '14 at 16:07
  • So, setting main charsets all over to utf8 in phpmyadmin has no effect at all? It's pointless, why is it possible? Is it only for viewing in phpmyadmin, and not for the database itself? – mowgli Jun 23 '14 at 16:11
  • 1
    How the data is stored inside the database and how clients are communicating with the database are two different things. MySQL will convert data on-the-fly to and from the connection charset, to make sure it can communicate properly with clients, regardless of their preferred charset. [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Jun 23 '14 at 16:13

1 Answers1

3

You have to execute this query after connecting to mysql:

SET NAMES 'utf8'
Marek
  • 7,337
  • 1
  • 22
  • 33