tags:

views:

36

answers:

2

I have a url string which i encode to utf8 at client side. When data recieved in server with my php script i can not see greek language characters! Could you please help me to convert them? data will be saved in mysql database .

A: 

When querying an MySQL database with PHP you also need to specify UTF-8 for the connection, like so:

mysql_query( "SET NAMES utf8", $database_connection );
mysql_query( "SET CHARACTER SET utf8", $database_connection );

Also make sure, that your database tables are encoded in UTF-8 (so you can see the greek characters when looking directly at the database tables) and you set UTF-8 headers via PHP.

There is a nice explanation for PHP, UTF-8 and several databases here: PHP and UTF-8 Howto

moontear
i get ??? on my mysql database! i have this code mb_internal_encoding( 'UTF-8' ); i also added mysql_query( "SET NAMES utf8", $con );mysql_query( "SET CHARACTER SET utf8", $con ); which i havent used before...thanks for that info...mysql database is set to UTF-8 Unicode (utf8) and connection collation is utf8_unicode_ci but i still get ???
stefanosn
So the Greek characters are displayed correctly via e.g. phpMyAdmin? Try different characters such as Umlauts öäü - insert them in your database and see if they are returned. Maybe a specific problem for Greek characters. Besides that your setup sounds good.
moontear
i went to a field and put greek inside and showed up but it does not work when i import through php. öäü these characters were shown correctly by the way...i am desperate...any help?
stefanosn
i forgot to tell that i used echo to return data on my browser before the import and greek chars showed up correctly but when i import i get ???
stefanosn
A: 

i figured out after hours that the configuration on the mysql server was ok. the problem was in the php script mysql_query( "SET NAMES utf8", $database_connection ); mysql_query( "SET CHARACTER SET utf8", $database_connection );

moontear was right about the lines but for me only worked by using the first line only. The second line caused the ??? on the database.

Thank you guys anyway.

stefanosn