12

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.

Suneth Kalhara
  • 1,211
  • 6
  • 20
  • 40
  • 2
    what the character encoding for the db, db connection, web page ? in short they should be identical –  Aug 04 '12 at 06:01
  • utf8_general_ci is the character encoding – Suneth Kalhara Aug 04 '12 at 06:04
  • nope mate, other texts are showing correctly http://tsiopelakos.dev-centiva.com/index.php?option=com_jumi&view=application&fileid=2&Itemid=322&txtTitle=&txtIsbn=&txtIsbn13=&txtAuthor=&txtEditor=&txtDfrom=&txtDto=&txtType=&txtPricefrom=&txtPriceto= – Suneth Kalhara Aug 04 '12 at 06:10
  • 1
    Read: [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Aug 04 '12 at 06:25
  • 1
    but is it the encoding on all three things i pointed to? –  Aug 04 '12 at 06:26
  • mysql_set_charset('utf8'); it is working, thank for help @deceze and dagon – Suneth Kalhara Aug 04 '12 at 06:32
  • 1
    Does this answer your question? [UTF-8 all the way through](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Dharman Mar 14 '20 at 22:54

6 Answers6

20

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

MilMike
  • 12,571
  • 15
  • 65
  • 82
16

Try this:

mysqli_set_charset($con, "utf8");

After you connect to DB.

Marios
  • 181
  • 1
  • 8
  • Nice Marios. Simple as that. It is actually a different way to change the encoding if you are using mysqli. – Leonidas Apr 30 '15 at 08:40
6

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'"); 
eyecatchUp
  • 10,032
  • 4
  • 55
  • 65
1

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!

Paschalis
  • 11,929
  • 9
  • 52
  • 82
1

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.

Filippos Zofakis
  • 561
  • 6
  • 12
nata Kart
  • 11
  • 1
0

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.

sadaf2605
  • 7,332
  • 8
  • 60
  • 103