Zend DB和编码 [英] Zend DB and encoding

查看:173
本文介绍了Zend DB和编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到一些比较奇怪的东西,我使用Zend Framework 1.10与Zend_Db_Table模块从数据库中读取一些数据。数据库本身,表和所有的字段都将其排序规则设置为utf8_general_ci,并且使用phpMyAdmin检查时,所有特殊字符都会在DB中正确格式化。此外,使用Zend_Db_Table保存工作正常,但是当我读取数据并将其回显到我的浏览器时,它将返回为ISO-8859-1,而不是UTF8。尝试使用json_encode(仅适用于UTF8字符串作为输入)对于从DB返回的值时,我注意到相同的事情。



如何设置Zend_Db_Table / Zend_Db_Row应该始终使用UTF8并返回一个UTF8值?我没有在我的应用程序中设置任何编码。



非常感谢您的帮助!

解决方案

请注意。在我的情况下,这个帮助:

  $ this-> db = new Zend_Db_Adapter_Pdo_Mysql(array(
'host' = $ config ['db_hostname'],
'username'=> $ config ['db_username'],
'password'=> $ config ['db_password'],
'dbname'=> $ config ['db_database'],
'charset'=>'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!

解决方案

Just note. In my case this one helped:

    $this->db = new Zend_Db_Adapter_Pdo_Mysql(array(
        'host'     => $config['db_hostname'],
        'username' => $config['db_username'],
        'password' => $config['db_password'],
        'dbname'   => $config['db_database'],
        'charset'  => 'utf8'
    ));

这篇关于Zend DB和编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆