Created
November 3, 2013 20:49
-
-
Save ReeMii/7294636 to your computer and use it in GitHub Desktop.
set time zone for MySQL connection in ZF2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function timezone_offset_string( $offset ) | |
{ | |
return sprintf( "%s%02d:%02d", ( $offset >= 0 ) ? '+' : '-', abs( $offset / 3600 ), abs( $offset % 3600 ) ); | |
} | |
$offset = timezone_offset_get( new DateTimeZone( 'Europe/Warsaw' ), new DateTime() ); | |
return array( | |
'service_manager' => array( | |
'factories' => array( | |
'Zend\Db\Adapter\Adapter' => function ($sm) use ($dbParams) { | |
return new Zend\Db\Adapter\Adapter(array( | |
'driver' => 'pdo', | |
'dsn' => 'mysql:dbname='.$dbParams['database'].';host='.$dbParams['hostname'], | |
'database' => $dbParams['database'], | |
'username' => $dbParams['username'], | |
'password' => $dbParams['password'], | |
'hostname' => $dbParams['hostname'], | |
'driver_options' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8;SET time_zone = "'.timezone_offset_string($offset).'";') | |
)); | |
}, | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment