PHP and MySQL TimeZone Synchronization

Info.Tech, PHP, SQL: Structured Query Language, Web Development Add comments

We all know the PHP and MySQL holds different timezone… what if we want both PHP and MySQL sync together by adjusting your PHP code only…

Here’s the solution:

<?php

define('TIMEZONE', 'Australia/Brisbane');

@date_default_timezone_set(TIMEZONE);

$dt = new DateTime();

// get time offset
$offset = $dt->format("P"); 

// update mysql timezone
mysql_query("SET time_zone='$offset';");

?>

 

Thanks to Craig Buckler…

Reference: http://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/




Comments are closed.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in