I\'m trying to insert an hebrew value into my mysql db, instead of hebrew the values looks like that.
שדגשדכעשד
Check the collation_connection:
show variables like '%collation%'
For future use, if you have this issue and you are using PDO and not mysqli, you will need to do it like this:
Hope this helps to future people that have this problem and using PDO. Best of luck.
you should make sure that:
Then you should be able to view Hebrew, or any other language, correctly in phpadmin
what finally helped me is to add the charset to the connection:
{"mysql:host=$host;dbname=$db;charset=utf8"}
I would say, in order to make sure that the values are passed well to the database I would add a die statment before inserting to the database and print the value, example:
die($_POST['thevalue']);
//insert to database.
//...
If it goes well, then the problem is on the database side, on the database I would try with this collation
| hebrew | ISO 8859-8 Hebrew | hebrew_general_ci | 1 |
as per http://dev.mysql.com/doc/refman/5.0/en/charset-mysql.html suggest.
But if it fail on the php side, reason can be, the server does not support Hebrew, make sure that on the html output document you use the correct metatag with
...
<meta charset="ISO 8859-8">
...
Let us knows how it proceed, good luck :)
Set charset to achieve the solution
While creating the database
CREATE DATABASE db_name
CHARACTER SET utf8
DEFAULT CHARACTER SET utf8
COLLATE utf8_general_ci
DEFAULT COLLATE utf8_general_ci
;
Or if the database is already created
CREATE TABLE table_name(
...
)
DEFAULT CHARACTER SET utf8
COLLATE utf8_general_ci;
OR while writing query
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn);
$re = mysql_query('SHOW VARIABLES LIKE "%character_set%";')or die(mysql_error());
while ($r = mysql_fetch_assoc($re)) {var_dump ($r); echo "<br />";}