Commit 8cea8dad authored by Dries's avatar Dries
Browse files

- Patch #331213 by Damien Tournoud: make it easier to write database driver.

parent 59ece2e3
...@@ -218,16 +218,19 @@ abstract class DatabaseConnection extends PDO { ...@@ -218,16 +218,19 @@ abstract class DatabaseConnection extends PDO {
protected $schema = NULL; protected $schema = NULL;
function __construct($dsn, $username, $password, $driver_options = array()) { function __construct($dsn, $username, $password, $driver_options = array()) {
// Merge in defaults. // Fallback to DatabaseStatementBase if the driver has not specified one.
$driver_options += array( $statement_class = isset($driver_options['statement_class']) ? $driver_options['statement_class'] : 'DatabaseStatementBase';
'statement_class' => 'DatabaseStatementBase', unset($driver_options['statement_class']);
);
// Because the other methods don't seem to work right. // Because the other methods don't seem to work right.
$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
// Call PDO::__construct and PDO::setAttribute. // Call PDO::__construct and PDO::setAttribute.
parent::__construct($dsn, $username, $password, $driver_options); parent::__construct($dsn, $username, $password, $driver_options);
if (!empty($driver_options['statement_class'])) {
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array($driver_options['statement_class'], array($this))); // Set a specific PDOStatement class if the driver requires that.
if (!empty($statement_class)) {
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array($statement_class, array($this)));
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment