如何在使用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

查看:178
本文介绍了如何在使用Bisna时在Zend Framework application.ini中的Doctrine 2中定义utf-8的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 ZendCasts cast 显示了在zend框架环境中使用doctrine 2的方法。

使用此配置,如何使连接使用utf-8字符集,因此SET NAMES'utf8'的魔力将发生?



我真正寻找的是一种使用application.ini文件配置它的方法。

如果使用此配置不可能,怎么能这样做通过代码?



谢谢。







$ b

UPDATE

看来有一个post连接事件处理这个,但我不知道如何通过application.ini设置它(如果可能的话所有)。

如果不是,我可以通过引导方法设置它吗?当依靠Bisna库时,引导方法是否会在任何其他原理连接代码运行之前运行?

解决方案

/ p>

  resources.doctrine.dbal.connections.default.parameters.driverOptions.1002 =SET NAMES'UTF8'
PDO :: MYSQL_ATTR_INIT_COMMAND


连接MySQL服务器时执行的命令。重新连接时,
会自动重新执行。
注意,这个常量只能在构造一个新的
数据库句柄时用于driver_options数组。



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 ?

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 ?

Thank you.

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 ?

解决方案

works fine for me

resources.doctrine.dbal.connections.default.parameters.driverOptions.1002 = "SET NAMES 'UTF8'"

1002 is the integer value of PDO::MYSQL_ATTR_INIT_COMMAND:

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屋!

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