diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php index a403404..daf4668 100644 --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -94,13 +94,6 @@ * * @var \PDO */ - private $pdoConnection; - - /** - * A reference to the actual PDO connection. - * - * @var \PDO - */ protected $connection; /** @@ -181,8 +174,7 @@ public function __construct(\PDO $connection, array $connection_options) { $connection->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array($this->statementClass, array($this))); } - $this->pdoConnection = $connection; - $this->connection = &$this->pdoConnection; + $this->connection = $connection; $this->connectionOptions = $connection_options; } @@ -206,14 +198,11 @@ public static function open(array &$connection_options = array()) { } * object may cause the number of maximum allowed connections to be exceeded. */ public function destroy() { - - // Destroy the reference to this connection. - unset($this->connection); - + // Destroy all references to this connection by setting them to NULL. // The Statement class attribute only accepts a new value that presents a // proper callable, so we reset it to PDOStatement. if (!empty($this->statementClass)) { - $this->pdoConnection->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array('PDOStatement', array())); + $this->connection->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array('PDOStatement', array())); } $this->schema = NULL; } diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php index 8fe1c45..3e73b49 100644 --- a/core/lib/Drupal/Core/Database/Database.php +++ b/core/lib/Drupal/Core/Database/Database.php @@ -161,7 +161,7 @@ $target = 'default'; } - if (!isset(self::$connections[$key][$target])) { + if (!isset(self::$connections[$key][$target]) || self::$connections[$key][$target] === NULL) { // If necessary, a new connection is opened. self::$connections[$key][$target] = self::openConnection($key, $target); } diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php index f081eff..c1cb885 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php @@ -49,6 +49,20 @@ class Connection extends DatabaseConnection { ]; /** + * The actual PDO object. + * + * @var \PDO + */ + private $actualConnection; + + /** + * A reference to the actual PDO object. + * + * @var \PDO + */ + protected $connection; + + /** * The list of PostgreSQL reserved key words. * * @see http://www.postgresql.org/docs/9.4/static/sql-keywords-appendix.html @@ -75,6 +89,9 @@ class Connection extends DatabaseConnection { public function __construct(\PDO $connection, array $connection_options) { parent::__construct($connection, $connection_options); + $this->actualConnection = $connection; + $this->connection = &$this->actualConnection; + // This driver defaults to transaction support, except if explicitly passed FALSE. $this->transactionSupport = !isset($connection_options['transactions']) || ($connection_options['transactions'] !== FALSE); @@ -157,6 +174,21 @@ public static function open(array &$connection_options = array()) { /** * {@inheritdoc} */ + public function destroy() { + // Destroy the reference to this connection. + unset($this->connection); + + // The Statement class attribute only accepts a new value that presents a + // proper callable, so we reset it to PDOStatement. + if (!empty($this->statementClass)) { + $this->actualConnection->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array('PDOStatement', array())); + } + $this->schema = NULL; + } + + /** + * {@inheritdoc} + */ public function query($query, array $args = array(), $options = array()) { $options += $this->defaultOptions();