views:

405

answers:

2

My website uses:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 
<html xmlns="http://www.w3.org/1999/xhtml"&gt; 

And this meta:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

I created my database and tables in phpMyAdmin making sure everything is set as utf8_unicode_ci (table, fields, database), even the connection collation.

When I insert some latin characters (accents, ñ and stuff like that) into the database using an standard form made in PHP, it works fine, I can display the saved data in my website no problem. But if I go to phpMyAdmin, all the latin characters are all messed up, something like ñññ.

If I try to fix that data in phpMyAdmin, then my website displays the data incorrectly, with weird symbols ���.

What in this world am I doing wrong? I've been trying to work this out for hours with no success.

Thank you all!

+3  A: 

As @Artefacto says, this could be a problem local to phpMyAdmin.

If phpMyAdmin is fine (i.e. set to UTF-8) and the data is still showing up weird, then look at whether your database connection using UTF-8 as well?

mysql_query("SET NAMES utf8") 

(or whatever you use as a database library) might help if it isn't.

Pekka
Yeah, I ran the query but everything stays the same.
Danny Herran
Pekka I was doing it all wrong. So, as soon as I instantiated my MySQL class I added a new line to run that query on every page and now everything works perfectly. Now, here comes another question: is it possible to set some sort of default so I don't need to run SET NAMES all the time?
Danny Herran
+1  A: 

If phpMyAdmin is showing ñññ instead of ñññ, that's because it's interpreting a UTF-8 bytestream as ISO-8859-1. So your database contents are probably correct, phpMyAdmin is just showing them in a wrong manner.

I'm not familiar with the application, but you can force the browser to read the page as UTF-8 (typically View > Encoding > UTF-8).

Artefacto
Good point, @OP check this first.
Pekka
I tried changing the Google Chrome and Firefox encoding to UTF-8 but it didn't work. phpMyAdmin is still displaying the weird symbols (yes, I restarted the browser).
Danny Herran
@Danny this is a setting on phpMyAdmin's front page (the "language" setting. You pick language and encoding there.)
Pekka
Ok I tried this in two servers, both behave the same. My phpMyAdmin home is set to MySQL charset: UTF-8 Unicode (utf8). I tried passing all the values in my form through utf8_decode() before the inserts and I can see everything ok in phpMyAdmin but not in my website, which means phpMyAdmin is the freaking problem. However, how come I can read data from a WordPress installation saved as UTF-8 and not the data saved from my own website?
Danny Herran