Link to home
Start Free TrialLog in
Avatar of ariestav
ariestav

asked on

Problem with Hebrew Characters in MySQL database. Hebrew characters appear as ??????.

I know this type of problem has already been posted, but I cannot store and retrieve Hebrew characters from a MySQL database.  I have read through this thread in detail, and have tried many things:

1.  Changed the character set property of the database to utf8.
2.  Changed the collation property of the database to utf8_bin.
3.  Changed the character set property of the table I need to pull data from to utf8.
4.  Changed the collation property of the tables i need to pull data from to utf8.
5.  Changed the character set property of the field that needs Hebrew characters to utf8.
6.  Changed the collation property of the field that needs Hebrew characters to utf8.

So, pretty much everything is set to utf8.  With navicat on the mac, I open up a console interface to the database.  I enter the following

mysql> show variables like "%%character%%";

and I receive this:

+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+  

for the same command on navicat on my windows machine I get this when I enter the above command:

+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | latin1                       |
| character_set_connection | latin1                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | latin1                       |
| character_set_server     | latin1                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+  

In my PHP script, I use this code before I query the database for the 'description' field values:

function pInfo($id, $col){

      $cxn = connect_to_db("connection.php");
      $sql = "SELECT name, title, image, description FROM frames, panels WHERE panels.FID = frames.ID AND panels.ID='$id'";
      mysql_query("SET character_set_client=utf8");
      mysql_query("SET character_set_connection=utf8");
      mysql_query("SET character_set_database=utf8");
      mysql_query("SET character_set_results=utf8");
      mysql_query("SET character_set_server=utf8");
      $result = mysql_query($sql, $cxn) or die("Couldn't retreive the panel information");
      $row = mysql_fetch_assoc($result);
      
      return stripslashes(utf8_decode($row[$col]));

}

When I echo the return value, I see ???? ???? ?? ??? in place of the Hebrew characters.  I am not sure why this is happening.  How can I ensure that I get the Hebrew characters to display on the webpage?

When I query the value for the 'description' field on navicat on the mac, I get this:

+---------------------------------------------------+
| description                                       |
+---------------------------------------------------+
| ???? ??'? ?????'? '???? ????
+---------------------------------------------------+
1 rows in set (0.26 sec)

When I query the value for the 'description' field on navicat on the windows machine, I get this;

+---------------------------------------------------+
| description                                       |
+---------------------------------------------------+
| ÜÓãÓ Óã'ç ÓÛÚÜ×'ç 'çÚÜ× ÓÛ×Ó |
+---------------------------------------------------+
1 rows in set (0.26 sec)

Why???  What is going on!?

How can I ensure that when I insert and pull data from this field, that it displays the Hebrew characters on my browser?

Thank you for your time and help!
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note the use of utf8_bin on database fields to accept hebrew characters.
Avatar of ariestav
ariestav

ASKER

Thanks for the link.  I took a look at that blog posting in my troubleshooting, and tried it, but the steps didn't seem to help because I am populating the database via navicat.  I don't think it has to do with the PHP side of things because when I query the actual db in navicat's console window on my windows box, I get the ????? pattern.  
Try to use latin1 instead of utf8. Alternatively, why don't insert the characters as html values. This way no matter what the encoding is you will be able to read them.
@khr:  use latin1 for which character set variable?  All of them?  Some of them, etc. . .

Thanks!
when you create the database through phpmyadmin, chose the name and next to it you will find the collation menu, chose latin1
Sorry, I forgot to mention I never used navicat, but I guess it will be the same as phpmyadmin you will need to define the collation of the database before creating it. So chose latin1 when you create the database
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial