Set mysql timezone at runtime via PHP

To set the timezone of mysql at runtime via php use the following code :

$c = mysqli_connect($host, $username, $password);
mysqli_query($c , "SET `time_zone` = '".date('P')."'");

This can be executed when the connection is established and it will set the timezone of mysql to whatever timezone php is set to. Fast and effective.






Last Updated On : 19th October 2011

Subscribe to get updates delivered to your inbox

About Silver Moon

Php developer, blogger and Linux enthusiast. He can be reached at [email protected]. Or find him on

Leave a comment