使用Bisna时如何在Zend Framework application.ini中定义Doctrine 2中utf-8的使用 [英] How to define the use of utf-8 in Doctrine 2 in Zend Framework application.ini, when using Bisna
问题描述
以下ZendCasts cast,展示了一种在zend框架环境中使用doctrine 2的方法.
使用这个配置,我怎样才能让连接使用 utf-8 字符集,这样 "SET NAMES 'utf8'"
的魔法就会发生?
The following ZendCasts cast, shows a way to use doctrine 2 in a zend framework environment.
Using this configuration, how can I make the connection use a utf-8 charset so the magic of "SET NAMES 'utf8'"
will happen ?
我真正想要的是一种使用 application.ini 文件配置它的方法.
如果使用此配置无法做到这一点,那么如何通过代码来完成?Bootstratp 文件中的 _initDoctrine
方法?
What I'm really searching for is a way to configure it using the application.ini file.
If that's not possible using this configuration, how can this be done by code ? an _initDoctrine
method in the Bootstratp file ?
谢谢.
更新
似乎有一个 post connect 事件可以处理这个问题,但我不知道如何通过 application.ini 设置它(如果可能的话).
如果没有,我可以通过引导方法进行设置吗?依赖 Bisna 库时,引导方法是否会在任何其他学说连接代码运行之前运行?
UPDATE
It appears there's a post connect event which handles this, but I don't see how can I set it up via application.ini (if possible at all).
If not, can I set it up via a bootstrap method ? Will the bootstrap method run before any other doctrine connection code run, when relying on the Bisna library ?
推荐答案
很适合我
resources.doctrine.dbal.connections.default.parameters.driverOptions.1002 = "SET NAMES 'UTF8'"
1002
是 PDO::MYSQL_ATTR_INIT_COMMAND
:
连接到 MySQL 服务器时执行的命令.将要重新连接时自动重新执行.注意,这个常量只能在构造新的驱动程序选项数组时使用数据库句柄.
Command to execute when connecting to the MySQL server. Will automatically be re-executed when reconnecting. Note, this constant can only be used in the driver_options array when constructing a new database handle.
这篇关于使用Bisna时如何在Zend Framework application.ini中定义Doctrine 2中utf-8的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!