2010-11-08 99 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)