I have an application in Zend Framework that has to run for a different time zone than the server. Is there an option to set the database server (MySQL in this case) time zone in application.ini?
My current options are:
resources.db.adapter = "Pdo_Mysql"
resources.db.params.charset = "utf8"
resources.db.params.driver_options.1002 = "SET NAMES utf8"
resources.db.params.host = "localhost"
resources.db.params.username = "usernam"
resources.db.params.password = "password"
resources.db.params.dbname = "databasename"
I know I can do something like SET timezone = 'Europe/London'
, but I really need to do it in the config file.
EDIT
Googling around I found that resources.db.params.driver_options.1002
should be setting the value for PDO::MYSQL_ATTR_INIT_COMMAND
.
Therefore resources.db.params.driver_options.1002 = "SET NAMES utf8, time_zone = 'Europe/London'"
should do the trick. But no luck so far.
FINAL EDIT
Found it. After a lot of searching and debugging I found the following code at Zend\Db\Adapter\Pdo\Mysql.php
if (!empty($this->_config['charset'])) {
$initCommand = "SET NAMES '" . $this->_config['charset'] . "'";
$this->_config['driver_options'][1002] = $initCommand; // 1002 = PDO::MYSQL_ATTR_INIT_COMMAND
}
As I have resources.db.params.charset = "utf8"
in my application.ini, it was overwriting PDO::MYSQL_ATTR_INIT_COMMAND
.
Deleting that line solved it.