为什么 MySQL 的 UNIX_TIMESTAMP 返回像“%qd”这样的奇数值?在 MySQL 5.5 中?
我正在尝试使用 PHP 中的 MySQL 查询时间数据,使用这种方法:
SELECT UNIX_TIMESTAMP( DATE_ADD( a.`date_time`, INTERVAL 1 DAY ) ) * 1000 AS time FROM `graph_values` AS a
在运行 MySQL 5.0.x 的生产服务器上,这会按预期返回 unix 时间戳。但是,在运行 MySQL 5.5.x 的开发服务器上,它返回字符串 "%qd"
。我尝试按照本页 MySQL 文档中的一些建议将结果CAST
转换为无符号整数:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp
当我转换 UNIX_TIMESTAMP
函数作为 UNSIGNED
时,查询返回不同的字符串 "%qu"
。
因此,很明显,奇怪的字符串受到返回数据的数据类型的影响,但我从未见过 PHP/MySQL 这样做。
注意:这是使用 PHP 和 mysqli。
有什么建议吗?
I am attempting to query time data from MySQL in PHP, using this sort of method:
SELECT UNIX_TIMESTAMP( DATE_ADD( a.`date_time`, INTERVAL 1 DAY ) ) * 1000 AS time FROM `graph_values` AS a
On a production server running MySQL 5.0.x, this returns a unix timestamp as expected. However, on a development server running MySQL 5.5.x it returns a string "%qd"
. I attempted to CAST
the result to an unsigned integer following some of the suggestions in the MySQL documentation on this page:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp
When I cast the result of the UNIX_TIMESTAMP
function as an UNSIGNED
, the query returned a different string, "%qu"
.
So, its obvious that the odd string is influenced by datatype of the data being returned, but I've never seen PHP/MySQL behave this way.
Note: This is using PHP and mysqli.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过将结果转换为其他类型(signed int、decimal)?
如果一切都出了问题 - 您可以使用类似 FROM_UNIXTIME(UNIX_TIMESTAMP(), '%s'); 的方法
以另一种方式“投射”它。
http://dev.mysql .com/doc/refman/5.5/en/date-and-time-functions.html#function_from-unixtime
不过,这不是我想要在生产代码中包含的东西......
Have you tried casting the result to some other type (signed int, decimal)?
If everything goes wrong - you may be able to use something like FROM_UNIXTIME(UNIX_TIMESTAMP(), '%s');
to "cast" it in another way.
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_from-unixtime
Not something I would want to have in my production code though...