1
0
mirror of synced 2025-01-18 22:41:43 +03:00

support for persistent connections, fixes #447

This commit is contained in:
zYne 2007-10-08 23:22:31 +00:00
parent 9a0ef8e97f
commit c69c0c5d53
2 changed files with 29 additions and 3 deletions

View File

@ -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;
}

View File

@ -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']);