php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74006 fractional seconds support missing
Submitted: 2017-01-27 09:12 UTC Modified: 2020-01-12 04:22 UTC
Votes:4
Avg. Score:4.5 ± 0.5
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:1 (25.0%)
From: smithlmk at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: PDO MySQL
PHP Version: 7 OS: windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: smithlmk at gmail dot com
New email:
PHP Version: OS:

 

 [2017-01-27 09:12 UTC] smithlmk at gmail dot com
Description:
------------
Fractional seconds are supported in MySQL DateTime(x) field types.
Writing such fields with fractional seconds via PDO into MySQL database is fully supported, however reading such fields directly via PDO won't return fractional seconds. A clumsy workaround is to wrap every DateTime field with a CONCAT function as shown in below test.


Test script:
---------------
(1) Create this table in MySQL:
CREATE TABLE `test` (
  `id` int(11) NOT NULL,
  `dt` datetime(3) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

(2) Connect db via PDO and do this:
$pdo->query("REPLACE INTO test (id, dt) VALUES (1, '2017-1-1 12:30:00.123')");
$a = $pdo->query("SELECT dt FROM test WHERE id = '1'")->fetch();
$b = $pdo->query("SELECT CONCAT(dt) AS dt FROM test WHERE id = '1'")->fetch();
var_dump($a, $b);

Expected result:
----------------
array(1) {
  'dt' =>
  string(23) "2017-01-01 12:30:00.123"
}
array(1) {
  'dt' =>
  string(23) "2017-01-01 12:30:00.123"
}

Actual result:
--------------
array(1) {
  'dt' =>
  string(19) "2017-01-01 12:30:00"
}
array(1) {
  'dt' =>
  string(23) "2017-01-01 12:30:00.123"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-27 10:38 UTC] smithlmk at gmail dot com
-PHP Version: 5.6.30 +PHP Version: 7
 [2017-01-27 10:38 UTC] smithlmk at gmail dot com
Updated PHP version, as this bug goes all the way up to PHP 7.
 [2017-02-01 13:30 UTC] andrew dot nester dot dev at gmail dot com
I was trying to reproduce your issue on latest 7.0 and 7.1 versions - looks like it's working, could you please retest it on latest versions?
 [2017-04-21 19:03 UTC] robert dot reinhard at bukwild dot com
Yes, I am experiencing in 7.0.13
 [2020-01-03 18:30 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-01-03 18:30 UTC] cmb@php.net
I cannot reproduce this with PHP 7.2.26 or later. Can you still
reproduce with any of the actively supported PHP versions[1]?  If
so, do you use any non-default configuration?  Also, which
database version do you use?

[1] <https://www.php.net/supported-versions.php>
 [2020-01-12 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC