0

When I fetch a record from my database, where the database, the table, and the row are all set to utf8_unicode_ci, I recieve a question boxed in a diagonal square in place of the correct unicode character; this is despite me also setting the HTML encoding on the page with:

 <meta charset="utf8">

I have a suspicion however it is to do with MySQL/PHP though because when I print_r the output the question marks are still displaying while a manually entered degree symbol (the symbol I should be seeing) works fine.

This SQL query also did nothing:

SET NAMES utf8;

Any ideas? I've checked every end of my setup.

marked-down
  • 9,958
  • 22
  • 87
  • 150
  • Are you having a font problem? Does your font support the extended character set? – Brad Dec 29 '13 at 08:19
  • Yep, a degree symbol displays correctly when entering it manually into the webpage, but does not if I retrieve a degree symbol from the db, for example. – marked-down Dec 29 '13 at 08:21

1 Answers1

3

utf8_unicode_ci is the collation, you need the character set as utf8 as example:

CREATE TABLE someTable DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci;

As adrienne states in their answer here:

make sure that all of the following are true:

  • The DB connection is using UTF-8
  • The DB tables are using UTF-8
  • The individual columns in the DB tables are using UTF-8
  • The data is actually stored properly in the UTF-8 encoding inside the database (often not the case if you've imported from bad sources, or changed table or column collations)
  • The web page is requesting UTF-8
  • Apache is serving UTF-8
Community
  • 1
  • 1
sergio
  • 5,210
  • 7
  • 24
  • 46
  • Ehhh, they changed the link, I will try to find in another source – sergio Dec 29 '13 at 08:32
  • Well, I found the article, but I have little to no terminal knowledge, so it's essentially useless. Sorry. – marked-down Dec 29 '13 at 08:37
  • Just check step by step if the following as I mentioned is true – sergio Dec 29 '13 at 08:39
  • setting the character set in the DB connection worked. Thank you. However your list is very good and I will run through it all anyway. – marked-down Dec 29 '13 at 09:20
  • 1
    Note that in order to fully support Unicode in MySQL, [you should use `utf8mb4` instead of what MySQL calls `utf8`](http://mths.be/utf8mb4). – Mathias Bynens Dec 30 '13 at 14:31
  • Once again, if you copy the words of another, you must properly quote them, as I did above, and provide a link to the original source. Please make sure to do this yourself in the future. – Brad Larson Dec 30 '13 at 16:09