5

I have a PHP web app with MySQL tables taking utf8 text. I recently converted the data from latin1 to utf8 along with the tables and columns accordingly. I did, however, forget to use mysql_set_charset and the latest incoming data I would assume came through the MySQL connection as latin1. I don't know what happens when latin1 comes in to a utf8 column, but it's causing some strange display issues for items like comma, quotes, ampersand, etc.

Now that mysql_set_charset is in place, it is pulling the data out with funky characters. Any way to convert the latin1-utf8 soup to straight utf8 now that i have the database connection resource using the correct charset?

4

1 回答 1

4

使用您的评论找到修复程序。这是似乎解决了我的问题的 SQL 行。

UPDATE table SET col = CONVERT(CONVERT(CONVERT(col USING latin1) USING binary) using utf8);

即使该列是 UTF8,它也会强制它以 latin1 格式提取数据,转换为二进制,转换为 utf8 并重新插入。

于 2010-07-05T16:41:43.790 回答