Bug #74006 [Opn]: fractional seconds support missing

From: Date: Fri, 27 Jan 2017 10:38:30 +0000
Subject: Bug #74006 [Opn]: fractional seconds support missing
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206976@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74006&edit=1

 ID:                 74006
 User updated by:    smithlmk at gmail dot com
 Reported by:        smithlmk at gmail dot com
 Summary:            fractional seconds support missing
 Status:             Open
 Type:               Bug
 Package:            PDO MySQL
 Operating System:   windows 7
-PHP Version:        5.6.30
+PHP Version:        7
 Block user comment: N
 Private report:     N

 New Comment:

Updated PHP version, as this bug goes all the way up to PHP 7.


Previous Comments:
------------------------------------------------------------------------
[2017-01-27 09:12:38] 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"
}


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74006&edit=1


Thread (6 messages)

« previous php.bugs (#206976) next »