Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在没有超级权限的情况下更改MySQL时区_Php_Mysql_Apache_Timezone - Fatal编程技术网

Php 在没有超级权限的情况下更改MySQL时区

Php 在没有超级权限的情况下更改MySQL时区,php,mysql,apache,timezone,Php,Mysql,Apache,Timezone,我在config.inc.php文件中添加了这一行 $query = "SET SESSION time_zone = 'Europe/Rome'"; if (mysql_query($query, DB_LINK) == FALSE) { die(mysql_error(DB_LINK)); } 它不会给我任何错误,但当我使用NOW()或CURRENT\u TIMESTAMP()函数时,它会用错误的时间保存记录 如果没有超级权限,我如何在MySQL中设置日期时区?呃,我不知道如何在M

我在config.inc.php文件中添加了这一行

$query = "SET SESSION time_zone = 'Europe/Rome'";
if (mysql_query($query, DB_LINK) == FALSE) {
    die(mysql_error(DB_LINK));
}
它不会给我任何错误,但当我使用
NOW()
CURRENT\u TIMESTAMP()
函数时,它会用错误的时间保存记录


如果没有超级权限,我如何在MySQL中设置日期时区?

呃,我不知道如何在MySQL中设置时区

但是我更喜欢用php设置时区

date_default_timezone_set('Europe/Rome');

呃,我不知道如何用mysql设置时区

但是我更喜欢用php设置时区

date_default_timezone_set('Europe/Rome');

假设您使用的是5.5,如果您看到,它会说:

mysql>设置时区=时区

它还说:

The current session time zone setting affects display and storage of time values that are zone-sensitive. This includes the values displayed by functions such as NOW() or CURTIME(), and values stored in and retrieved from TIMESTAMP columns. Values for TIMESTAMP columns are converted from the current time zone to UTC for storage, and from UTC to the current time zone for retrieval.

The current time zone setting does not affect values displayed by functions such as UTC_TIMESTAMP() or values in DATE, TIME, or DATETIME columns. Nor are values in those data types stored in UTC; the time zone applies for them only when converting from TIMESTAMP values. If you want locale-specific arithmetic for DATE, TIME, or DATETIME values, convert them to UTC, perform the arithmetic, and then convert back. 
因此,在不使用
会话的情况下尝试它,看看它是否有效,并检查
是否选择@@SESSION.time_zone;
为您提供正确的时区

编辑:您的数据库可能有问题。我刚刚在我的一个数据库(5.5.8)上尝试了这个,它成功了,但在5.0.51上失败了。因此,您可能需要升级数据库

mysql> select CURRENT_TIMESTAMP();
+---------------------+
| CURRENT_TIMESTAMP() |
+---------------------+
| 2011-05-29 14:33:06 |
+---------------------+
1 row in set (0.00 sec)

mysql> set time_zone = 'Europe/Rome';
Query OK, 0 rows affected (0.00 sec)

mysql> select CURRENT_TIMESTAMP();
+---------------------+
| CURRENT_TIMESTAMP() |
+---------------------+
| 2011-05-29 16:33:11 |
+---------------------+
1 row in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.5.8-log |
+-----------+
1 row in set (0.00 sec)

假设您使用的是5.5,如果您看到,它会说:

mysql>设置时区=时区

它还说:

The current session time zone setting affects display and storage of time values that are zone-sensitive. This includes the values displayed by functions such as NOW() or CURTIME(), and values stored in and retrieved from TIMESTAMP columns. Values for TIMESTAMP columns are converted from the current time zone to UTC for storage, and from UTC to the current time zone for retrieval.

The current time zone setting does not affect values displayed by functions such as UTC_TIMESTAMP() or values in DATE, TIME, or DATETIME columns. Nor are values in those data types stored in UTC; the time zone applies for them only when converting from TIMESTAMP values. If you want locale-specific arithmetic for DATE, TIME, or DATETIME values, convert them to UTC, perform the arithmetic, and then convert back. 
因此,在不使用
会话的情况下尝试它,看看它是否有效,并检查
是否选择@@SESSION.time_zone;
为您提供正确的时区

编辑:您的数据库可能有问题。我刚刚在我的一个数据库(5.5.8)上尝试了这个,它成功了,但在5.0.51上失败了。因此,您可能需要升级数据库

mysql> select CURRENT_TIMESTAMP();
+---------------------+
| CURRENT_TIMESTAMP() |
+---------------------+
| 2011-05-29 14:33:06 |
+---------------------+
1 row in set (0.00 sec)

mysql> set time_zone = 'Europe/Rome';
Query OK, 0 rows affected (0.00 sec)

mysql> select CURRENT_TIMESTAMP();
+---------------------+
| CURRENT_TIMESTAMP() |
+---------------------+
| 2011-05-29 16:33:11 |
+---------------------+
1 row in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.5.8-log |
+-----------+
1 row in set (0.00 sec)

如果您使用time
+01:00
指定时间偏移,该怎么办?@zerkms感谢您的回答,但它不起作用:(如果您使用time
+01:00
指定时间偏移,该怎么办?@zerkms感谢您的回答,但它不起作用:(感谢您的回答。它正确设置了MySQL时区,但对于当前的\u时间戳不起作用。)()函数。@Aegidius:copy粘贴我们请在mysql控制台示例中添加您的查询。一切都会正常运行。感谢您的回答。CURRENT_TIMESTAMP()->2011-05-29 07:53:04-SET time_zone='Europe/Rome'->0行-CURRENT_TIMESTAMP()->2011-05-29 07:55:04-version()->5.0.91-log…:(是的,在5.0系列上没有正常工作。我认为你运气不好。你可能想看看函数的使用情况。我真的非常感谢你的帮助。我刚刚删除了所有MySQL函数,并用PHP函数替换了它们。再次感谢:)谢谢你的回答。它正确设置了MySQL时区,但是对于CURRENT_TIMESTAMP()函数它不起作用。@Aegidius:复制粘贴我们请在MySQL控制台示例中添加你的查询。一切都应该正常谢谢你的回答。CURRENT_TIMESTAMP()->2011-05-29 07:53:04-设置时区=‘欧洲/罗马’->0行-当前时间戳()->2011-05-29 07:55:04-版本()->5.0.91-log…:(是的,在5.0系列上没有正常工作。我认为你运气不好。你可能想看看函数的使用情况。我真的非常感谢你的帮助。我刚刚删除了所有MySQL函数,并用PHP函数替换了它们。再次感谢:)