Reputation: 4715
I'm not sure if someone has asked this question before or not but I didn't find any. While I hadn't set connection charset in PDO and table collation was utf8_percian_ci
, so all data has been stored in unreadable characters like سلام
that is سلام
in Persian.
Before setting charset by adding mysql:charset=utf8mb4;
to PDO DNS I was able to retrieve all data correctly but now I see سلام
instead of سلام
in browser.
My website is a blog and now it seems I have to reenter all the texts and posts and then restore them to be saved correctly. That's a disaster!
I used mb_detect_encoding()
for both سلام
& سلام
and found out that both of them are UTF-8. This is so funny to search "How to convert utf8 to utf8 ?" and absolutely I get no expected result.
Is there anyway to convert سلام
to سلام
using MySQL ? If not, I thought another way could be using PHP to read old data then convert and insert into database again.
What should I do ?
Upvotes: 0
Views: 603
Reputation: 125995
You can simply do:
UPDATE my_table SET my_column = BINARY CONVERT(my_column USING latin1)
(where latin1
is the character set in which your connection was set at the time of insertion).
Upvotes: 2