Skip to content

Commit

Permalink
OdbcDriver: added option 'microseconds'
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 9, 2018
1 parent c8dfb1f commit 2870fb9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Dibi/Drivers/OdbcDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -32,6 +33,9 @@ class OdbcDriver implements Dibi\Driver
/** @var int|null Affected rows */
private $affectedRows;

/** @var bool */
private $microseconds = true;


/**
* @throws Dibi\NotSupportedException
Expand Down Expand Up @@ -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'];
}
}


Expand Down Expand Up @@ -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#');
}


Expand Down

0 comments on commit 2870fb9

Please sign in to comment.