From 4bfd31422527a1020a65f70673bae3ed4ce5de62 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 9 Aug 2018 22:51:35 +0200 Subject: [PATCH] OdbcDriver: added option 'microseconds' --- src/Dibi/Drivers/OdbcDriver.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Dibi/Drivers/OdbcDriver.php b/src/Dibi/Drivers/OdbcDriver.php index bab379df..4a30b359 100644 --- a/src/Dibi/Drivers/OdbcDriver.php +++ b/src/Dibi/Drivers/OdbcDriver.php @@ -19,6 +19,7 @@ use Dibi; * - password (or pass) * - persistent (bool) => try to find a persistent link? * - resource (resource) => existing connection resource + * - microseconds (bool) => use microseconds in datetime format? */ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector { @@ -33,6 +34,9 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** @var bool */ private $autoFree = true; + /** @var bool */ + private $microseconds = true; + /** @var int|false Affected rows */ private $affectedRows = false; @@ -78,6 +82,10 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector if (!is_resource($this->connection)) { throw new Dibi\DriverException(odbc_errormsg() . ' ' . odbc_error()); } + + if (isset($config['microseconds'])) { + $this->microseconds = (bool) $config['microseconds']; + } } @@ -286,7 +294,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) { $value = new Dibi\DateTime($value); } - return $value->format('#m/d/Y H:i:s.u#'); + return $value->format($this->microseconds ? '#m/d/Y H:i:s.u#' : '#m/d/Y H:i:s#'); }