PHP MySQL Greek letters showing like ???? marks-ThrowExceptions

Exception or error:

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
Image for SQL Query Results

But when i show this my site frontend using mysql_fetch array and when echo it shows as below
enter image description here

Anyone know how to fix this error
thank you.

How to solve:

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

Answer:

Try this:

mysqli_set_charset($con, "utf8");

After you connect to DB.

Answer:

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'"); 

Answer:

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:

  1. Dropped MySQL procedures/functions (make sure you backup your code)

  2. Changed default charset of MySQL (using MySQL Workbench, right click on your database name-has a db icon..)

  3. re-created the MySQL procedures/functions

Also, I left intact the qxxx ‘s fix!

Answer:

You don’t have to drop tables or anything.
Use MySQL Workbench and go to each table. Change the Collation to utf8 – default collation or utf8 – general ci.
Then do the same for each column with type Varchar – it is found at the bottom of the window.

Answer:

I faced the same problem while implementing Greek Characters. The solutions like mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
did not work for me. After Googling, I found that, the character set for the database collation should be made greek_general_ci along with the field where data would be stored like categoryname etc. This solved my problem.

Leave a Reply

Your email address will not be published. Required fields are marked *