简体   繁体   中英

convert utf8 characters using PHP or MySQL

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM