Tag Archives: timezone

Force MySQL timezone on RDS in a Symfony1 project

If you need to force a specific MySQL timezone for your symfony1 project you should edit ProjectConfiguration.class.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class ProjectConfiguration extends sfProjectConfiguration
{
    ...
    public function configureDoctrineConnection(Doctrine_Connection $connection)
    {
        $mysql_timezone = sfConfig::get('app_mysql_timezone', 'SYSTEM');
        try
        {
            $connection->exec('SET time_zone = "' . $mysql_timezone . '"');
        } catch (Exception $e)
        {
            /* I'm here because if an invalid timezone
             * is given I'm silently (and cowardly),
             * ignoring it and using MySQL's default
             * timezone instead */

        }
    }
    ...
}