Mysql – Setting the timezone in MySQL on every connection using Zend PHP

amazon-rdsMySQLzend-framework

My company just recent moved our MySQL database to and instance Aamazon Web Service's RDS.

The problem is the application relies on time zone information and the timezone in MySQL (under RDS) is set to UTC and can't be changed.

So I'm wondering how to change it on a perconnection basis in my Zend Framework.

I'm not really sure where to start with this so any suggestions?

Best Answer

function setDbTimeZone(Zend_Db_Adapter_Abstract $dbAdapter, $timeZone)
{
    $dbAdapter->exec("SET time_zone='$timeZone'");
}

Usage:

$dbAdapter = new Zend_Db_Adapter_Pdo_Mysql([
    // ...
]);

setDbTimeZone($dbAdapter, 'US/Pacific');
Related Topic