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