0

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?

Valentin Golev
  • 9,965
  • 10
  • 60
  • 84

2 Answers2

4

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

David Snabel-Caunt
  • 57,804
  • 13
  • 114
  • 132
  • 1
    Np - it's not explicitly covered in the manual, but a common requirement for sure! More questions on SO will make it easier for everyone :) – David Snabel-Caunt Oct 24 '09 at 16:00
0

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

Community
  • 1
  • 1
tawfekov
  • 5,084
  • 3
  • 28
  • 51