Mysql_query (& quot; SETtime_zone = '+ 8:00' & quot;) ordie ('Time zone setting failed. please contact the administrator! ');
The MySQL time zone is the server's time zone by default.
You can run the following command to view
View the time zone
SQL code
. Mysql> show variables like '% time_zone % ';
. + ------------------ + -------- +
. | Variable_name | Value |
. + ------------------ + -------- +
. | System_time_zone | CST |
. | Time_zone | SYSTEM |
. + ------------------ + -------- +
. 2 rows in set (0.00 sec)
Note: If the value of time_zone is SYSTEM, it indicates that its time zone is the same as that of the operating SYSTEM.
You can modify my. cnf
Add under [mysqld]
Default-time-zone = timezone
To modify the time zone. For example:
Default-time-zone = '+ 8:00'
Remember to restart msyql.
Note that you must add it under [mysqld]. Otherwise, the error message "unknown variable 'default-time-zone = + 8:00 '" appears.
You can also run the set time_zone = timezone command.
For example, Beijing time (GMT + 0800)
Set time_zone = '+ 8:00 ';
> In the PHP program>
Date_default_timezone_set ('prc') or die ('Time zone setting failed. please contact the administrator! ');
> Query or use a database>
// Once the database is connected, it is followed by the MySQL time code.
Mysql_query ("SET time_zone = '+ 8:00'") or die ('Time zone setting failed. please contact the administrator! ');