From c69c0c5d53a04a192062e97110116034cdbcf39a Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 8 Oct 2007 23:22:31 +0000 Subject: [PATCH] support for persistent connections, fixes #447 --- lib/Doctrine/Connection.php | 10 +++++++++- lib/Doctrine/Manager.php | 22 ++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 1238e9836..5cfc33b9b 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -177,6 +177,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun $this->options['dsn'] = $adapter['dsn']; $this->options['username'] = $adapter['user']; $this->options['password'] = $adapter['pass']; + + $this->options['other'] = array(); + if (isset($adapter['other'])) { + $this->options['other'] = array(Doctrine::ATTR_PERSISTENT => $adapter['persistent']); + } + } $this->setParent($manager); @@ -336,7 +342,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun if (extension_loaded('pdo')) { if (in_array($e[0], PDO::getAvailableDrivers())) { - $this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']); + $this->dbh = new PDO($this->options['dsn'], $this->options['username'], + $this->options['password'], $this->options['other']); + $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $found = true; } diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index c626abb60..b09cd0df2 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -231,8 +231,13 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera public function openConnection($adapter, $name = null, $setCurrent = true) { if (is_object($adapter)) { - if ( ! ($adapter instanceof PDO) && ! in_array('Doctrine_Adapter_Interface', class_implements($adapter))) { - throw new Doctrine_Manager_Exception("First argument should be an instance of PDO or implement Doctrine_Adapter_Interface"); + if ( ! ($adapter instanceof PDO) && + ! in_array('Doctrine_Adapter_Interface', class_implements($adapter))) { + + $msg = 'First argument should be an instance of PDO or ' + . 'implement Doctrine_Adapter_Interface'; + + throw new Doctrine_Manager_Exception($msg); } $driverName = $adapter->getAttribute(Doctrine::ATTR_DRIVER_NAME); @@ -369,6 +374,19 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera // append port to dsn if supplied $parts['dsn'] .= ';port=' . $parts['port']; } + + $options = array(); + + if (isset($parts['query']) && $parts['query'] != null ) { + // parse options + parse_str($parts['query'], $options); + } + + if (isset($options['persistent'])) { + // set persistent + $parts['persistent'] = (bool) $options['persistent']; + } + break; default: throw new Doctrine_Manager_Exception('Unknown driver '.$parts['scheme']);