0

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 ?

5
  • have you tried with utf8_general_ci ? Commented Dec 20, 2013 at 14:53
  • I have tried that. The problem is not just about output encoding Commented Dec 20, 2013 at 14:54
  • @HarshalMahajan No, but I know just changing the collation won't make any change. Commented Dec 20, 2013 at 14:55
  • possible duplicate of How to convert wrongly encoded data to UTF-8? Commented Dec 20, 2013 at 14:59
  • @deceze Exactly works ! You're the man of unicode ;) Commented Dec 20, 2013 at 15:12

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.