Skip to content

Commit 2870fb9

Browse files
committed
OdbcDriver: added option 'microseconds'
1 parent c8dfb1f commit 2870fb9

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/Dibi/Drivers/OdbcDriver.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* - password (or pass)
2222
* - persistent (bool) => try to find a persistent link?
2323
* - resource (resource) => existing connection resource
24+
* - microseconds (bool) => use microseconds in datetime format?
2425
*/
2526
class OdbcDriver implements Dibi\Driver
2627
{
@@ -32,6 +33,9 @@ class OdbcDriver implements Dibi\Driver
3233
/** @var int|null Affected rows */
3334
private $affectedRows;
3435

36+
/** @var bool */
37+
private $microseconds = true;
38+
3539

3640
/**
3741
* @throws Dibi\NotSupportedException
@@ -62,6 +66,10 @@ public function __construct(array &$config)
6266
if (!is_resource($this->connection)) {
6367
throw new Dibi\DriverException(odbc_errormsg() . ' ' . odbc_error());
6468
}
69+
70+
if (isset($config['microseconds'])) {
71+
$this->microseconds = (bool) $config['microseconds'];
72+
}
6573
}
6674

6775

@@ -238,7 +246,7 @@ public function escapeDateTime($value): string
238246
if (!$value instanceof \DateTimeInterface) {
239247
$value = new Dibi\DateTime($value);
240248
}
241-
return $value->format('#m/d/Y H:i:s.u#');
249+
return $value->format($this->microseconds ? '#m/d/Y H:i:s.u#' : '#m/d/Y H:i:s#');
242250
}
243251

244252

0 commit comments

Comments
 (0)