php - 在 MySQL 中是否有等效于 PHP 的 `date_default_timezone_set()` 的东西?

标签 php mysql

这在 PHP 中非常有效

date_default_timezone_set('my/timezone');

$actualDate = date('Y-m-d');

现在做查询时,我喜欢做

INSERT INTO articles (title, insert_date) VALUES ('My Title', now())

问题是 MySQL 中的 now() 与在 PHP 中计算的结果不同(因此与设置的时区不同)。

有没有办法,比如 SQL 查询,来设置 MySQL 的默认时区?

谢谢

最佳答案

http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html

If you have the SUPER privilege, you can set the global server time zone value at runtime with this statement:

mysql> SET GLOBAL time_zone = timezone;

Per-connection time zones. Each client that connects has its own time zone setting, given by the session time_zone variable. Initially, the session variable takes its value from the global time_zone variable, but the client can change its own time zone with this statement:

mysql> SET time_zone = timezone;

关于php - 在 MySQL 中是否有等效于 PHP 的 `date_default_timezone_set()` 的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/896305/

相关文章:

php mysql 根据第一个插入ID执行2个插入语句

php - 从我的 pdo 调用创建正确的数据结构

php - 在队列 MYSQL 中运行查询

php - 更改 Zend_Validate_EmailAddress 中的 error_message

php - 将自定义二进制格式 blob 插入 SQL 中

mysql - 在另一个存储过程中调用存储过程

mysql - 铁路服务器错误? ( rails 3)在 Windows 中

mysql - 表 'tbl_name' 被指定了两次,既作为 'UPDATE' 的目标又作为单独的数据源

php - 如何获取带条件的mysql查询结果

php - mysql php搜索表单-想要在选择查询之前从用户输入中删除特殊字符