Zend DB 和编码
我刚刚遇到了一些相当奇怪的事情,我使用 Zend Framework 1.10 和 Zend_Db_Table 模块从数据库读取一些数据。数据库本身、表和相关字段都将其排序规则设置为“utf8_general_ci”,并且当使用 phpMyAdmin 检查时,所有特殊字符在数据库中显示格式正确。另外,使用 Zend_Db_Table 保存效果很好,但是当我读取数据并将其回显到浏览器时,它会以 ISO-8859-1 的形式返回,而不是以 UTF8 的形式返回。当尝试对从数据库返回的值使用 json_encode (仅适用于 UTF8 字符串作为输入)时,我注意到同样的事情。
我如何设置 Zend_Db_Table/Zend_Db_Row 应该始终使用 UTF8 并返回一个 UTF8 值?我还没有在我的应用程序中设置任何有关编码的内容。
非常感谢您的帮助!
I have just encountered something rather strange, I use the Zend Framework 1.10 with the Zend_Db_Table module to read some data from a databse. The database itself, the table and the fields in question all have their collation set to "utf8_general_ci" and all special chars appear correctly formatted in the DB when checked with phpMyAdmin. Also, saving with Zend_Db_Table works just fine, yet when I read the data and just echo it to my browser it is returned as ISO-8859-1, not as UTF8. I noticed the same thing when trying to use json_encode (which only works with UTF8 strings as input) on a value returned from the DB.
How can I set that Zend_Db_Table/Zend_Db_Row should always work with UTF8 and return me an UTF8 value? I have not set anything regarding encoding in my app yet.
Thanks a lot for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请注意。就我而言,这有帮助:
Just note. In my case this one helped:
就像罗伯特·贝西克说的。
like robertbasic said.
好吧,刚刚找到了解决方案,尝试这样做:
希望这可以在某个时候帮助其他人:)
Ok just found the solution, try to do this:
Hope this helps somebody else at some point :)
您也可以将具有所需值的“charset”键放入配置中,DB驱动程序将执行适当的查询(取决于使用的DBMS)。看来目前(版本 1.10.5)几乎所有驱动程序都支持这一点。
Also you can just put "charset" key with desired value into config and DB-driver will execute an appropriate query (depending on DBMS used). It seems to be that currently (version 1.10.5) almost all drivers support that.