2010-11-08 130 views
4

我在stackoverflow上搜索过帖子,发现了一些类似的帖子。但我认为这是一个不同的帖子。我的PHP & Mysql服务器的时区全部设置为“UTC”。PHP strtotime返回不同​​值的Mysql UNIX_TIMESTAMP

在我使用时间戳字段的表,价值为 “2010-11-08二时54分15秒”,我用这样的SQL:

SELECT id, 
     updated, 
     second(updated) , 
     unix_timestamp(updated) 
    FROM `transaction` 
where id = 56 

得到这个:

id updated    second unix 
-------------------------------------------- 
56 2010-11-08 02:54:15 15  1289184879 

然后我在PHP中使用这样的:

echo strtotime("2010-11-08 02:54:15"); 

得到这个:

1289184855 

不同的是24秒。

我检查这些时间戳http://www.unixtimestamp.com/index.php PHP的结果是正确的。所以mysql的unix_timestamp函数有bug? Mysql版本是:5.1.41

+1

仅供参考,'SELECT UNIX_TIMESTAMP('2010-11-08 02:54:15');'给我在MySQL 5.1.37上的1289152455。 – deceze 2010-11-08 03:35:39

+0

我也是,@deceze,我在MySQL 5.1.41上就像OP一样。 – ceejayoz 2010-11-08 03:37:24

+0

我无法在5.1.49上重现,使用与TIMESTAMP或DATETIME相同的值。 – 2010-11-08 03:46:45

回答

4

这被确认是一个在5.1.44中修复的bug。

有关详细信息,请参见http://bugs.mysql.com/bug.php?id=51918,错误海报完全发现此问题。

您将别无选择,只能升级以避免它的外观。

+0

虽然该票中的另一张海报仍然存在[5.1.45中的相同问题](http://bugs.mysql.com/bug.php?id=52624)。很奇怪。 – deceze 2010-11-08 08:46:42

+0

只有关于5.1.45和5.1.46中的windows版本,以前的版本中都没有再提到这个bug,所以5.1.52应该都很好,但测试是唯一确定的方法。 – Payload 2010-11-09 01:12:01

0

我无法在Linux上重现MySQL 5.1.41。也许这只是Windows?

[email protected]:~$ mysql 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 295 
Server version: 5.1.41 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 

mysql> select unix_timestamp("2010-11-08 02:54:15"); 
+---------------------------------------+ 
| unix_timestamp("2010-11-08 02:54:15") | 
+---------------------------------------+ 
|       1289206455 | 
+---------------------------------------+ 
1 row in set (0.00 sec) 

mysql> exit 
Bye 
[email protected]:~$ php -a 
Interactive shell 

php > echo strtotime("2010-11-08 02:54:15"); 
1289206455 
php > exit 
[email protected]:~$ mysql 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 297 
Server version: 5.1.41 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 

mysql> select from_unixtime(1289206455); 
+---------------------------+ 
| from_unixtime(1289206455) | 
+---------------------------+ 
| 2010-11-08 02:54:15  |                           
+---------------------------+                           
1 row in set (0.00 sec)