« Getting subversion to ignore multiple files in a directory | Main | Audio to Rasmus's PHP for Rich Internet Applications »

MySQL 5.0 and TimeZones

Little bug with MySQL 5.0.X and PHP 5.1.4. In previous versions of PHP and MySQL < 5.0.0 you used to be able to set an environment variable called "TZ" to specify your timezone:

<?php
putenv
("TZ=Africa/Johannesburg");
?>

But with MySQL 5.0.0 or later one needs to specify your timezone as follows (note in this example I'm using PEAR::DB):

<?php
/**
* Override the timezone for our MySQL session
*/
$result = $dbh->query("SET @@session.time_zone='Africa/Johannesburg'");
if (
PEAR::isError($result)) {
    die (
$result->getMessage());
}
?>

More information about this can be found on the MySQL Time Zone Support page.



TrackBack

TrackBack URL for this entry:
http://www.powertrip.co.za/blog/mt-tb.cgi/533

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)