0

Here's a sample string, stored in a MySQL database, running on a Linux server: ™</p>

That's the single TM character, which is represented as 0x2122 in UTF-16BE, or 0xE284A2 in UTF-8

The database table is encoded in utf8-unicode-ci. I'm running PHP on another Linux server, which uses an internal encoded (as reported by mb_internal_encoding) of ISO-8859-1, which uses the same encoding for the character as UTF-8.

When I run a SQL query to get the string, it returns 0x0099, which is its representation in Windows-1252.

How would that even happen, and how can I fix it to return in a more sensible codepage?

4

1 回答 1

0

您观察到的行为是由于默认的 MySQL 客户端字符集造成的。

您可以覆盖默认值,并指定要用于客户端连接的字符集。如果您使用的是 mysqli,请执行以下操作:

$mysqli->set_charset('utf8');

看:

http://php.net/manual/en/mysqlinfo.concepts.charset.php

http://dev.mysql.com/doc/refman/5.5/en/charset-connection.html

于 2013-01-10T23:03:04.903 回答