David Caunt

PHP and Zend Framework Engineer

Subscribe to my RSS feed

Posts Tagged ‘mysql’

Zend Framework Pitfalls Part 2 – Zend_Db Won’t Use the Query Cache with MySQL

November 28th, 2009

This one’s not limited to Zend Framework, but is actually a ‘problem’ in MySQL. I think it is worth covering, as the paragraph in the manual is easily missed.

From the MySQL manual:

Before MySQL 5.1.17, prepared statements do not use the query cache. Beginning with 5.1.17, prepared statements use the query cache under certain conditions, which differ depending on the preparation method

This means that if you’re running MySQL 5.0.x, not uncommon at the time of writing, your applications are not going to benefit from the query cache. There’s a simple workaround, however:

If you’re using Pdo, set the following driver option:

$pdoParams = array(
    PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
);
 
$params = array(
    'host'           => '127.0.0.1',
    'username'       => 'webuser',
    'password'       => 'xxxxxxxx',
    'dbname'         => 'test',
    'driver_options' => $pdoParams
);

Zend_Config_Ini [parse_ini_file()] doesn’t support class constants, so ini users will have to supply the value of PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1000, in their configs:

resources.db.adapter         = pdo_mysql
resources.db.params.host     = localhost
resources.db.params.username = webuser
resources.db.params.password = xxxxxxxx
resources.db.params.dbname   = myDb
resources.db.params.driver_options.1000 = true

Top