MySQL 和 PHP 出现计数错误

Getting counting errors with MySQL and PHP

我正在制作一个程序来计算统计页面数据库中的日志,我的查询计算每个月有多少日志。问题是我计算了日志,我的数字和数据库给我的数字之间存在计数差异。我把数据分解了,这样会更容易阅读。也许我做错了查询,但这是我现在能想到的最好的。也许有人可以解决这个问题或让我知道我做错了什么。

查询

select distinct FROM_UNIXTIME(log_date,"%M, %Y") AS month, count(*) as numberOfVisits
from support.support_logs
group by month
order by log_date desc;

输出

month           numberOfVisits
"March, 2015"       2
"February, 2015"    5
"January, 2015"     11
"December, 2014"    18
"November, 2014"    19
"October, 2014"     5

数据

PHP time()  Converted to readable
1413849800  2014-10-21 00:03:20
1413849800  2014-10-21 00:03:20
1413849800  2014-10-21 00:03:20
1413936200  2014-10-22 00:03:20
1413936200  2014-10-22 00:03:20

1414973000  2014-11-03 00:03:20
1414973000  2014-11-03 00:03:20
1414973000  2014-11-03 00:03:20
1414973000  2014-11-03 00:03:20
1415750600  2014-11-12 00:03:20
1415750600  2014-11-12 00:03:20
1415837000  2014-11-13 00:03:20
1416096200  2014-11-16 00:03:20
1416096200  2014-11-16 00:03:20
1416096200  2014-11-16 00:03:20
1416096200  2014-11-16 00:03:20
1416096200  2014-11-16 00:03:20
1416096200  2014-11-16 00:03:20
1416701000  2014-11-23 00:03:20
1416701000  2014-11-23 00:03:20
1416701000  2014-11-23 00:03:20
1416701000  2014-11-23 00:03:20
1416701000  2014-11-23 00:03:20

1417392200  2014-12-01 00:03:20
1418342600  2014-12-12 00:03:20
1418342600  2014-12-12 00:03:20
1418342600  2014-12-12 00:03:20
1418429000  2014-12-13 00:03:20
1418429000  2014-12-13 00:03:20
1418429000  2014-12-13 00:03:20
1418429000  2014-12-13 00:03:20
1418429000  2014-12-13 00:03:20
1418429000  2014-12-13 00:03:20
1418429000  2014-12-13 00:03:20
1418429000  2014-12-13 00:03:20
1419033800  2014-12-20 00:03:20
1419033800  2014-12-20 00:03:20
1419465800  2014-12-25 00:03:20
1419465800  2014-12-25 00:03:20
1419465800  2014-12-25 00:03:20
1419465800  2014-12-25 00:03:20
1419984200  2014-12-31 00:03:20

1420589000  2015-01-07 00:03:20
1420589000  2015-01-07 00:03:20
1420589000  2015-01-07 00:03:20
1420589000  2015-01-07 00:03:20
1420589000  2015-01-07 00:03:20
1421885000  2015-01-22 00:03:20
1421971400  2015-01-23 00:03:20
1421971400  2015-01-23 00:03:20
1421971400  2015-01-23 00:03:20
1422317000  2015-01-27 00:03:20
1422317000  2015-01-27 00:03:20

1423267400  2015-02-07 00:03:20
1423267400  2015-02-07 00:03:20
1423267400  2015-02-07 00:03:20
1423267400  2015-02-07 00:03:20

1425168200  2015-03-01 00:03:20
1426118600  2015-03-12 00:03:20
1426118600  2015-03-12 00:03:20

如果您使用 UNIX_TIMESTAMP() 和 FROM_UNIXTIME() 在 TIMESTAMP 值和 Unix 时间戳值之间转换,转换是有损的,因为映射不是双向一对一的.详情参见UNIX_TIMESTAMP()函数的说明。 这意味着

1425168200  2015-03-01 00:03:20

上面的值是一个示例,unix_timestamp 如何有损您的 mysql 服务器在 3 月 1 日读取,而在其他时区

仍然是 2 月 28 日

解决方案是更改 MySQL 或 PHP 上的时区,这样两台服务器上的日期时间就会一致