How do I set the time zone of MySQL?

后端 未结 20 3771
闹比i
闹比i 2020-11-21 07:07

On one server, when I run:

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2009-05-30 16:54:29 |
+---------         


        
20条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-21 07:28

    If you're using PDO:

    $offset="+10:00";
    $db->exec("SET time_zone='".$offset."';");
    

    If you're using MySQLi:

    $db->MySQLi->query("SET time_zone='".$offset."';");
    

    More about formatting the offset here: https://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/

提交回复
热议问题