2

this might look like a similar issues for utf8 and Arabic language with MySQL database but i searched for result and found none..

my database endocing is set to utf8_general_ci , i had my php paging to be encoded as ansi by default the arabic language in database shows as : ãÌÑÈ

but i changed it to utf8 , if i add new input to database , the arabic language in database shows as : زين

i dont care how it show indatabase as long as it shows normally in php page , after changing the php page to utf8 , when adding input than retriving it , if show result as it should .
but the old data which was added before converting the page encoding to uft8 show like this : �����

i tried a lot of methods for fixis this like using iconv in ssh and php , utf8_decode() utf8_encode() .. and more but none worked .

so i was hoping that you have a solution for me here ?


update :: Main goal was solved by retrieving data from php page in old encoding ' windows-1256' than update it from ssh .


but one issue left ::

i have some text that was inserted as 'windows-1256' and other that was inserted as 'utf-8' so now the windows encoding was converted to utf-8 and works fine , but the original utf-8 was converted as well to something unreadable , using iconv in php, with old page encoding ..

so is there a way to check what encoding is original in order to convert or not ?

3
  • read this stackoverflow.com/questions/6859018/… Commented Feb 7, 2014 at 3:36
  • as i said , my database endocing is set to utf8_general_ci . the issue is how to show the old data which was inserted by ANSI PHP page .. Commented Feb 7, 2014 at 3:40
  • Hi did you get any solution for this problem? Commented Nov 21, 2019 at 7:21

1 Answer 1

0

Try run query set name utf8 after create a DB connection, before run any other query.

Such as :

$dbh = new PDO('mysql:dbname='.DB_NAME.';host='.DB_HOST, DB_USER, DB_PASSWORD); $dbh->exec('set names utf8'); 
Sign up to request clarification or add additional context in comments.

10 Comments

For you old data, please create a backup table in old format, then use your php code to re-input it to new table
If you have your old table as backup, and it can be read by your old php code somehow. Then, even it is shows as : زين, you can try to reinsert them to you new table via your php.
the old php page can read only old code as it is ANSI encoded , and new one will read the utf8 correctly , so if i do the update it has to be from the new page in order to be read as utf8 , but when doing so , i will be left with something like this: ظ…ظˆظ‚ط¹ ..
You can use you old php page to read it properly, then convert it to utf8, then export it to a utf-8 sql query text file. Then, you can manually run that query to db, or let your UTF8 php to run it.
this will work if we are talking about a small db .. my db is more than 70mb ..what you are talking about is more than 1 page conversion process and as i see , i cant figure how to be done with such db . do you have a way for that or .. ?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.