0

I have an odd problem. I'm running MySQL 5.1 on Windows (but production server is Debian Linux and same issue occurs).

I'm using mysql_query() to UPDATE a table. The description field can occasionally have special characters like degree symbol, plus/minus, etc.

I have looked at the query before being sent to mysql_query() and it looks fine. I run the exact query through mysql client and it works fine. but passing the query to mysql_query() causes of of the special characters to be prefixed with an accented A:

BAKE AT 365 - 383 °F FOR 3 HOURS.

Not sure what the heck is going on here, any ideas? I've googled and tried setting everything to UTF-8 and more - whatever I could find.

I'm out of options, converting to html entities is not a option because this text is converted to PDF and various output in other technologies like Access 97 that don't render the entity properly - so the print out has ° which confuses the guys reading the documents.

Suggestions?

4

1 回答 1

0

UTF-8 中的度数符号恰好对应于 Latin-1 编码中的字符 °。您没有正确设置数据库连接编码,因此数据库误解了您发送的字符。连接数据库后设置mysql_set_charset为。'utf8'

请参阅在 Web 应用程序中从前到后处理 Unicode以及每个程序员绝对、肯定需要了解编码和字符集以使用文本以获取更深入的信息。

于 2012-09-24T14:16:20.987 回答