views:

35

answers:

1

Hi,

I want to make sure something is write.

My database tables are utf8_unicode_ci and my site encoding and header is utf-8 etc and so on.

I done a test and in my guestbook i entered this:

á
ʵßăāÇϢϞﻨ☺ 

▓ ▓ẻ ▓ẻṎ

۞ ݤ

Now great it displays on the webpage like it should and i tested other languages to etc, but on checking this in phpmyadmin it is showing in the text field value area in phpmyadmin as:

á
ʵßăÄÇϢϞﻨ☺ 

▓ ▓ẻ ▓ẻṎ

۞ ݤ

Can someone tell me why this is showing like this in phpmyadmin? i mean is it stored like that and it that normal or should it be stored exactly as i typed it? It is happening on all foreign language like chineese etc aswell, basically all foreign languages.

I checked to ensure and in phpmyadmin it says:

MySQL connection collation: utf8_unicode_ci and MySQL charset: UTF-8 Unicode (utf8)

Maybe it's phpmyadmin? if so what must i do to get phpmyadmin to display utf-8 correctly, either that or mysql is not storing it rite although it displays fine when outputting to webpage.

Thanks for any help, btw must say this is a great site, very quick support and very nice helpful people on here, so thanks to everyone who has already helped me since joining earlier on today! :)

Thank you!

Now

+1  A: 

No, it is not PhpMyAdmin. It has always been using UTF-8 all the time.

The DB connection in your PHP application itself is likely not using UTF-8. Although the bytes which are transferred from one to the other side are the same, they are been encoded and decoded using the wrong charset, namely the platform default one which is most likely ISO-8859-1 as per the patterns of the Mojibake characters (first character of the UTF-8 pair/triplet becomes then often Ã, Â, Ä and like).

You need to let PHP inform MySQL using mysql_set_charset() that you're working with UTF-8 data:

mysql_set_charset("utf8");

Note that this only works in PHP >= 5.2.3 and MySQL >= 5.0.7, else you need to do a SET NAMES query instead, see also the aforelinked PHP manual. Also note that you need to truncate and refill the DB with new data, you can't redisplay it on the webpage anymore without converting it back using some SQL script.

BalusC
Hi, i placed that what you have given above just before the mysql_query that inserts the data into database and it still the same not showing rite.Also i did not think i would need to specify that as phpmyadmin shows:MySQL connection collation: utf8_unicode_ci and MySQL charset: UTF-8 Unicode (utf8) Not sure why it won't work thou ?Thanks
PHPLOVER
If anything is looking "right" in the PHP side, but not in the DB side, then this is really the only possible cause (unless PhpMyAdmin itself has some bug, but none comes to mind for this, you should however check its response header to be on the safe side). Have you read the two notes which I added afterwards?
BalusC
Hey, sorry, I made a little mistake. I automatically wrote `UTF-8`, but it should have been `utf8` (MySQL is probably very strict in this). Give it a retry.
BalusC
Hi BalusC,My MySQL version is from phpmyadmin: MySQL client version: 5.0.51aAlso i don't know what you mean by "Also note that you need to truncate and refill the DB with new data, you can't redisplay it on the webpage anymore without converting it back using some SQL script"Thanks
PHPLOVER
Hi,I changed it to utf8 but in phpmyadmin it now shows as: "áʵß??Ç????? ?? ?????"
PHPLOVER
With that part I meant that you should delete all existing rows and retest (I of course assume that the existing data in DB is just all testing/stub data). As to the new problem with the questionmarks, it means that either PHP itself didn't use UTF-8 to process the submitted data (the HTTP input), or that the INSERT didn't take place using UTF-8. The first part is to be fixed by configuring mbstring as per [this cheatsheet](http://developer.loftdigital.com/blog/php-utf-8-cheatsheet) and the second part is to be fixed using `mysql_set_charset()` beforehand.
BalusC
Yes i am just testing, it's working now it seems that for some reason my tables went back to the default latin1_swedish_ci for some strange reason. Thanks for the help :)
PHPLOVER
That's also a possible cause of those questionmarks, I only didn't take this into consideration since the tables were correct as per the original question. Glad you fixed it :) You're welcome.
BalusC
I'm glad for your help, everyone is so nice and friendly and great support!Thanks!
PHPLOVER
Note that collation is column-specific in MySQL, so changing a table's default collation to UTF-8 doesn't actually change the charset of existing columns. Previously you will have had an ISO-8859-1 connection and ISO-8859-1 columns, which works in that you get the same bytes out as you put in, but would confuse any other app that tried to look at the data (like phpmyadmin) and would get case-insensitive comparison wrong.
bobince