Synchronize PHP and MySQL Timezones -


my timezone through php umt using code:

$timezone = date_default_timezone_get(); // utc echo "the current server timezone is: " . $timezone."<br />"; echo date('y-m-d h:i:s');   //  2015-04-10 00:08:05 

and mysql gives me pkt system timezone , time 2015-04-10 05:14:38

select @ @system_time_zone // pkt select now( ) , unix_timestamp( now( ) ) // 2015-04-10 05:14:38 

due time difference, unable fetch correct records database using php.

how can synchronize php , mysql timezones both both return same time?

is possible change timezone of mysql using php?

i have tried this, i'm getting error:

warning: pdo::__construct(): server requested authentication method unknown client 

you can use mysql's function

convert_tz(timestamp_field,[mysql_timezone],[php_timezone]) 

or change servers timezone in php:

date_default_timezone_set([timezone]); 

php date_default_timezone_set

or change mysql timezone:

set global time_zone = [timezone] 

that statement change timezone mysql, if restart server use default timezone. can set default timezone on startup, here link: set default timezone mysql

hope helps


Popular posts from this blog