From 2870fb9b31b384ed18441c8712f4ab94c0c11eb5 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 6779c4bee..10b6d1ef5 100644 --- a/src/Dibi/Drivers/OdbcDriver.php +++ b/src/Dibi/Drivers/OdbcDriver.php @@ -21,6 +21,7 @@ * - 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 { @@ -32,6 +33,9 @@ class OdbcDriver implements Dibi\Driver /** @var int|null Affected rows */ private $affectedRows; + /** @var bool */ + private $microseconds = true; + /** * @throws Dibi\NotSupportedException @@ -62,6 +66,10 @@ public function __construct(array &$config) if (!is_resource($this->connection)) { throw new Dibi\DriverException(odbc_errormsg() . ' ' . odbc_error()); } + + if (isset($config['microseconds'])) { + $this->microseconds = (bool) $config['microseconds']; + } } @@ -238,7 +246,7 @@ public function escapeDateTime($value): string if (!$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#'); }