PHP如何从Mysql返回datetime(6)? [英] PHP How to return datetime(6) from Mysql?

查看:137
本文介绍了PHP如何从Mysql返回datetime(6)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我查询dateTime时(6)PHP正在截断我的6个小时秒。

When I query a dateTime(6) PHP is truncating my 6 fractional seconds.

以下是我的PHP代码示例:

Here is an example of my php code:

$sql = 'SELECT date FROM tbl';
        $statement = $connection->prepare($sql);
        $statement->execute();
        $statement->store_result();
        $statement->bind_result($date);
        while ($statement->fetch()) 
        {
        echo $date."\n";
        }

这将返回2014-01-08 21:31:15而不是2014- 01-08 21:31:15.995000这是表中存储的。如何获得表中实际存储的内容?

This returns 2014-01-08 21:31:15 instead of 2014-01-08 21:31:15.995000 which is what is stored in the table. How can I get what is actually stored in the table?

推荐答案

问题是您正在使用的PHP适配器与Mysql。据我所见,您正在使用PDO适配器来获取查询结果。但是,此适配器不支持小数秒(YYYY-MM-DD HH:MM:SS.F)。

The problem is with the PHP Adapter you are using to communicate with Mysql. As far as I can see you are using PDO adapter to fetch the query result. However, this adapter does not support fractional seconds (YYYY-MM-DD HH:MM:SS.F).

PDO适配器支持YYYY-MM-DD HH: MM:SS并自动将datetime列的值格式化为此格式。

The PDO adapter supports YYYY-MM-DD HH:MM:SS and automatically formats the value of datetime columns to this format.

这是PDO适配器本身的一个错误。请参阅以下链接以获得参考:
http://grokbase.com/t/php/php-bugs/11524dvh68/php-bug-bug-54648-new-pdo-forces-format-of-datetime -fields

This is a bug in PDO adapter itself. Please find the link below for reference: http://grokbase.com/t/php/php-bugs/11524dvh68/php-bug-bug-54648-new-pdo-forces-format-of-datetime-fields

这篇关于PHP如何从Mysql返回datetime(6)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆