i am using wamp for localhost, its mysql version is 5.5. After i finished my website i wanted to upload it to my website (shared hosting). which runs (5.1) but i cant insert arabic letters anymore.
when i insert any field in arabic, it gets stored as weird characters "ضووع".
it was doing great on my pc, but not online.
the database is myisam by default, but all tables are innodb with utf8_general_ci. also this is the same database i used on my machine (innodb by default) (I've imported it into my new database on the shared hosting).
so far i tried those things after making the connection
mysql_set_charset('utf8');
and
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET COLLATION_CONNECTION = 'utf8_unicode_ci'");
what can i do more?
this happened to me once, i was using htmlentities()
, but when i used htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
the problem solved.
hope you have the same problem.
Provided you are using mysql_set_charset('utf8');
and not getting any errors when inserting data, that means you are correctly giving the database utf-8. On another side, you could have tables defined in some other charset, such as Windows-1256 (labeled 'cp1256'
by MySQL), but that doesn't seem possible from the output you see, which is UTF-8 decoded as Windows-1252.
So the possibility I see is that you are echoing data from the database, and seeing this strings. You need to tell the browser the data is in UTF-8 as well, before sending any output:
<?php
header("Content-Type: text/html; charset=utf-8");
If you are already doing this or this doesn't help, your data was probably incorrectly converted in the import process.
If this is the case, and you can reimport, ensure that when exporting the data comes out as utf-8, and when importing the exported data, it is treated as utf-8.