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: 2017-01-27 10:38 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:
Status: Open Package: PDO MySQL
PHP Version: 7 OS: windows 7
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Oct 22 12:01:26 2018 UTC