开发者

zend_db query on connect

开发者 https://www.devze.com 2022-12-09 20:17 出处:网络
I want the query \'SET NAMES utf8\' to 开发者_开发知识库execute before any other queries. But, if I execute it in the beginning of my app, it forces Zend_Db to connect to the Database, even if I\'m n

I want the query 'SET NAMES utf8' to 开发者_开发知识库execute before any other queries.

But, if I execute it in the beginning of my app, it forces Zend_Db to connect to the Database, even if I'm not running any other queries. It isn't cool: My app processes lots of requests without any queries, only using cache.

How to ask Zend_Db to run 'SET NAMES utf8' right after connection?


Sure, simply pass the 'charset' option in with the adapter params. You can do this via Zend_Config or in code:

$params = array(
    'host'           => '127.0.0.1',
    'username'       => 'webuser',
    'password'       => 'xxxxxxxx',
    'dbname'         => 'test',
    'charset'        => 'utf8'
);

$db = Zend_Db::factory('Pdo_Mysql', $params);

Reference: http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.connecting.parameters


check this link for config option , its more easier How to make PDO run SET NAMES utf8 each time I connect, In ZendFramework.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号