[英]Character encoding issues: MySQL 5.0 + PHP 5.2
I have a MySQL database with an InnoDB table containning utf8_general_ci varchar fields. 我有一个带有InnoDB表的MySQL数据库,该表包含utf8_general_ci varchar字段。 When I fetch them through PHP (via PEAR::MDB2) and try to output them (via Smarty), I get ??? 当我通过PHP获取它们(通过PEAR :: MDB2)并尝试输出它们(通过Smarty)时,我得到了? symbols. 符号。 I would like to know how to fix that problem, which is most likely caused by PHP. 我想知道如何解决该问题,这很可能是由PHP引起的。
Good information to know: 要了解的好信息:
Basically, it seems that PHP or MySQL transforms the UTF-8 data contained within the database to ISO-8859-1 at some point during the query/fetch process, and that is what I want to fix. 基本上,似乎PHP或MySQL在查询/获取过程中的某个时刻将数据库中包含的UTF-8数据转换为ISO-8859-1,这就是我要解决的问题。
I've done a lot of searching but haven't found any solution, and I'm hoping the problem lies in a setting somewhere. 我已经做了很多搜索,但是还没有找到任何解决方案,我希望问题出在某个地方。 I'd like to avoid having to use htmlentities() or utf8_encode(), however that might be the only way to go until PHP6 shows up. 我想避免使用htmlentities()或utf8_encode(),但是这可能是直到出现PHP6的唯一方法。
Thank you for your input on this! 感谢您对此的投入!
You need to execute a few queries to tell it to use UTF-8 for the connection (the default is indeed Latin-1). 您需要执行一些查询,以告知它使用UTF-8进行连接(默认确实是Latin-1)。 Here's what I use: 这是我使用的:
SET CHARACTER SET = "utf8";
SET character_set_database = "utf8";
SET character_set_connection = "utf8";
SET character_set_server = "utf8";
I know some of these seem overkill, but they have been tested and do seem to work quite well... 我知道其中一些似乎过于矫kill过正,但它们已经过测试,并且确实运作得很好。
我的猜测是,数据到达数据库时未经过utf-8编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.