PHP MySQL Greek letters showing like ???? marks
I have a table with some text and text is greek letters, when i use sql tool and select the data from this table is showing correctly
But when i show this my site frontend using mysql_fetch array and when echo it shows as below
Anyone know how to fix this error thank you.
try the following:
after you connect to the mysql, do this query to make sure that you are using UTF8:
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
make sure that in HTML (head) you are using the right encoding, try:
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
if this does not help, try different encoding, like ISO-8859-1
Try this:
mysqli_set_charset($con, "utf8");
After you connect to DB.
Leaving this here for those who come to this site via Google because they have the same issue but use PDO instead (like me) - you should be fine with:
$dns = "mysqli:host=localhost;dbname=db_name";
$pdo = new PDO($dns, 'db_user', 'db_pass',
array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
$pdo->exec("SET CHARACTER SET 'utf8'");
I wasted many hours till i figured this out.
Intro: Greek characters were appearing wrong in mysql. I applied qxxx answer in PHP and worked fine. Then I had to migrate everything to a new host, and then the problem reappeared.
What was wrong?
The MySQL's schema charset was set to latin. The stored procedures had inherited MySQL's schema charset for their parameters.
So what I did:
Dropped MySQL procedures/functions (make sure you backup your code)
Changed default charset of MySQL (using MySQL Workbench, right click on your database name-has a db icon..)
re-created the MySQL procedures/functions
Also, I left intact the qxxx 's fix!