From: Michael M Slusarz Date: Thu, 12 Aug 2010 19:26:34 +0000 (-0600) Subject: Use Horde_Db_Pear injector as much as possible X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=fd9e8a39cfc5fc2a8bf638de5be3a5204dc8ef34;p=horde.git Use Horde_Db_Pear injector as much as possible --- diff --git a/beatnik/lib/Driver/pdnsgsql.php b/beatnik/lib/Driver/pdnsgsql.php index 612916460..62b3a99f1 100644 --- a/beatnik/lib/Driver/pdnsgsql.php +++ b/beatnik/lib/Driver/pdnsgsql.php @@ -417,7 +417,7 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver * * @access private * - * @return boolean True on success; exits (Horde::fatal()) on error. + * @return boolean True on success. */ function _connect() { @@ -425,54 +425,8 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver return true; } - try { - $result = Horde::assertDriverConfig($this->_params, 'pdnsqsql', array('phptype'), 'PowerDNS Generic SQL'); - } catch (Exception $e) { - Horde::logMessage($e, 'ERR'); - throw $e; - } - - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_write_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if (is_a($this->_write_db, 'PEAR_Error')) { - Horde::fatal($this->_write_db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = &DB::connect($params, - array('persistent' => !empty($params['persistent']))); - if (is_a($this->_db, 'PEAR_Error')) { - Horde::fatal($this->_db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db =& $this->_write_db; - } - - $this->_connected = true; + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'beatnik', 'storage'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'beatnik', 'storage'); return true; } diff --git a/beatnik/lib/Driver/sql.php b/beatnik/lib/Driver/sql.php index 395f8a139..b75c0bae9 100644 --- a/beatnik/lib/Driver/sql.php +++ b/beatnik/lib/Driver/sql.php @@ -214,7 +214,7 @@ class Beatnik_Driver_sql extends Beatnik_Driver * * @access private * - * @return boolean True on success; exits (Horde::fatal()) on error. + * @return boolean True on success. */ function _connect() { @@ -222,60 +222,8 @@ class Beatnik_Driver_sql extends Beatnik_Driver return true; } - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_write_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if (is_a($this->_write_db, 'PEAR_Error')) { - Horde::fatal($this->_write_db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = &DB::connect($params, - array('persistent' => !empty($params['persistent']))); - if (is_a($this->_db, 'PEAR_Error')) { - Horde::fatal($this->_db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db =& $this->_write_db; - } - - $this->_connected = true; + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'beatnik', 'storage'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'beatnik', 'storage'); return true; } diff --git a/crumb/lib/Driver/sql.php b/crumb/lib/Driver/sql.php index 9ebd3297b..d12dbd156 100644 --- a/crumb/lib/Driver/sql.php +++ b/crumb/lib/Driver/sql.php @@ -102,60 +102,8 @@ class Crumb_Driver_sql extends Crumb_Driver { return true; } - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset', 'table')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_write_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if (is_a($this->_write_db, 'PEAR_Error')) { - throw new Horde_Exception_Prior($this->_write_db); - } - - // Set DB portability options. - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = &DB::connect($params, - array('persistent' => !empty($params['persistent']))); - if (is_a($this->_db, 'PEAR_Error')) { - throw new Horde_Exception_Prior($this->_write_db); - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db =& $this->_write_db; - } - - $this->_connected = true; + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'crumb', 'storage'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'crumb', 'storage'); return true; } diff --git a/fima/lib/Driver/sql.php b/fima/lib/Driver/sql.php index 23dc94ffc..af8765227 100644 --- a/fima/lib/Driver/sql.php +++ b/fima/lib/Driver/sql.php @@ -1052,38 +1052,12 @@ class Fima_Driver_sql extends Fima_Driver { */ function initialize() { - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if (is_a($this->_db, 'PEAR_Error')) { - return $this->_db; - } - - /* Set DB portability options. */ - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); + try { + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'fima', 'storage'); + } catch (Horde_Exception $e) { + return PEAR::raiseError($e->getMessage()); } - $this->_connected = true; - return true; } diff --git a/folks/lib/Driver/sql.php b/folks/lib/Driver/sql.php index 6777d50ee..3872fadf8 100644 --- a/folks/lib/Driver/sql.php +++ b/folks/lib/Driver/sql.php @@ -567,61 +567,12 @@ class Folks_Driver_sql extends Folks_Driver { * Attempts to open a persistent connection to the SQL server. * * @return boolean True on success. + * @throws Horde_Exception */ private function _connect() { - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset', 'table')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_write_db = DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if ($this->_write_db instanceof PEAR_Error) { - throw new Horde_Exception_Prior($this->_write_db); - } - - // Set DB portability options. - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = DB::connect($params, - array('persistent' => !empty($params['persistent']))); - if ($this->_db instanceof PEAR_Error) { - throw new Horde_Exception_Prior($this->_db); - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db =& $this->_write_db; - } + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'folks', 'storage'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'folks', 'storage'); return true; } diff --git a/folks/lib/Friends/sql.php b/folks/lib/Friends/sql.php index 8bd989d9b..e3c6f0089 100644 --- a/folks/lib/Friends/sql.php +++ b/folks/lib/Friends/sql.php @@ -197,66 +197,17 @@ class Folks_Friends_sql extends Folks_Friends { * Attempts to open a persistent connection to the SQL server. * * @return boolean True on success. + * @throws Horde_Exception */ protected function _connect() { - $this->_params = Horde::getDriverConfig('storage', 'sql'); + $this->_params = array_merge(array( + 'blacklist' => 'folks_blacklist', + 'friends' => 'folks_friends' + ), $this->_params); - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - if (!isset($this->_params['friends'])) { - $this->_params['friends'] = 'folks_friends'; - } - if (!isset($this->_params['blacklist'])) { - $this->_params['blacklist'] = 'folks_blacklist'; - } - - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_write_db = DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if ($this->_write_db instanceof PEAR_Error) { - throw new Horde_Exception_Prior($this->_write_db); - } - - // Set DB portability options. - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = DB::connect($params, - array('persistent' => !empty($params['persistent']))); - if ($this->_db instanceof PEAR_Error) { - throw new Horde_Exception_Prior($this->_db); - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db =& $this->_write_db; - } + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'folks', 'storage'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'folks', 'storage'); return true; } diff --git a/framework/Core/lib/Horde/Core/Factory/DbPear.php b/framework/Core/lib/Horde/Core/Factory/DbPear.php index 7a72fbb78..166cad95b 100644 --- a/framework/Core/lib/Horde/Core/Factory/DbPear.php +++ b/framework/Core/lib/Horde/Core/Factory/DbPear.php @@ -55,35 +55,56 @@ class Horde_Core_Factory_DbPear * Return the DB instance. * * @param string $type Either 'read' or 'rw'. + * @param string $app The application. + * @param mixed $type The type. If this is an array, this is used as + * the configuration array. * * @return DB The singleton DB instance. * @throws Horde_Exception */ - public function getDb($type = 'rw') + public function getDb($type = 'rw', $app = 'horde', $type = null) { - if (isset($this->_instances[$type])) { - return $this->_instances[$type]; + global $registry; + + $sig = hash('md5', serialize($type . '|' . $app . '|' . $type)); + + if (isset($this->_instances[$sig])) { + return $this->_instances[$sig]; + } + + $pushed = ($app == 'horde') + ? false + : $registry->pushApp($app); + + $config = is_array($type) + ? $type + : $this->getConfig($type); + + /* Determine if we we are not using splitread or if we are using the + * base SQL config. */ + if ((($type == 'read') && empty($config['splitread'])) || + (isset($config['driverconfig']) && + ($config['driverconfig'] == 'horde'))) { + $this->_instances[$sig] = $this->getDb($type); + return $this->_instances[$sig]; } - $params = array_merge(array( - 'database' => '', - 'hostspec' => '', - 'password' => '', - 'username' => '' - ), $GLOBALS['conf']['sql']); if ($type == 'read') { - $params = array_merge($params, $params['read']); + $config = array_merge($config, $config['read']); } - Horde::assertDriverConfig($params, 'sql', array('charset', 'phptype'), 'SQL'); + Horde::assertDriverConfig($config, 'sql', array('charset', 'phptype')); /* Connect to the SQL server using the supplied parameters. */ - $db = DB::connect($params, array( - 'persistent' => !empty($params['persistent']), - 'ssl' => !empty($params['ssl']) + $db = DB::connect($config, array( + 'persistent' => !empty($config['persistent']), + 'ssl' => !empty($config['ssl']) )); if ($db instanceof PEAR_Error) { + if ($pushed) { + $registry->popApp(); + } throw new Horde_Exception($db); } @@ -98,9 +119,20 @@ class Horde_Core_Factory_DbPear break; } - $this->_instances[$type] = $db; + if ($pushed) { + $registry->popApp(); + } + + $this->_instances[$sig] = $db; return $db; } + /** + */ + public function getConfig($type) + { + return Horde::getDriverConfig($type, 'sql'); + } + } diff --git a/framework/Core/lib/Horde/Core/Factory/Vfs.php b/framework/Core/lib/Horde/Core/Factory/Vfs.php index 64e310ddd..c1b2b4723 100644 --- a/framework/Core/lib/Horde/Core/Factory/Vfs.php +++ b/framework/Core/lib/Horde/Core/Factory/Vfs.php @@ -85,8 +85,19 @@ class Horde_Core_Factory_Vfs ? $conf['vfs'] : $conf[$name]; - if ($vfs['type'] == 'sql') { - $vfs['params'] = Horde::getDriverConfig($name, 'sql'); + switch ($vfs['type']) { + case 'sql': + $db_pear = $this->_injector->getInstance('Horde_Db_Pear'); + $vfs['db'] = $db_pear->getDb('read', 'horde', 'vfs'); + $vfs['writedb'] = $db_pear->getDb('rw', 'horde', 'vfs'); + $vfs['params'] = $db_pear->getConfig('vfs'); + break; + + case 'sql_file': + $db_pear = $this->_injector->getInstance('Horde_Db_Pear'); + $vfs['db'] = $db_pear->getDb('rw', 'horde', 'vfs'); + $vfs['params'] = $db_pear->getConfig('vfs'); + break; } return $vfs; diff --git a/framework/DataTree/DataTree/sql.php b/framework/DataTree/DataTree/sql.php index d0e5162d1..6c3820b71 100644 --- a/framework/DataTree/DataTree/sql.php +++ b/framework/DataTree/DataTree/sql.php @@ -1848,61 +1848,21 @@ class DataTree_sql extends DataTree { /** * Attempts to open a connection to the SQL server. * - * @return boolean True. + * @return mixed True or PEAR_Error. */ function _init() { - Horde::assertDriverConfig($this->_params, 'sql', - array('phptype', 'charset'), - 'DataTree SQL'); - - $default = array( - 'database' => '', - 'username' => '', - 'password' => '', - 'hostspec' => '', + try { + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'datatree'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'datatree'); + } catch (Horde_Exception $e) { + return PEAR::raiseError($e->getMessage()); + } + + $this->_params = array_merge(array( 'table' => 'horde_datatree', 'table_attributes' => 'horde_datatree_attributes', - ); - $this->_params = array_merge($default, $this->_params); - - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_write_db = DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']), - 'ssl' => !empty($this->_params['ssl']))); - if (is_a($this->_write_db, 'PEAR_Error')) { - return $this->_write_db; - } - - // Set DB portability options. - $portability = DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS; - if ($this->_write_db->phptype == 'mssql') { - $portability |= DB_PORTABILITY_RTRIM; - } - $this->_write_db->setOption('portability', $portability); - - /* Check if we need to set up the read DB connection - * seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = DB::connect($params, - array('persistent' => !empty($params['persistent']), - 'ssl' => !empty($params['ssl']))); - if (is_a($this->_db, 'PEAR_Error')) { - return $this->_db; - } - - // Set DB portability options - $portability = DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS; - if ($this->_db->phptype == 'mssql') { - $portability |= DB_PORTABILITY_RTRIM; - } - $this->_db->setOption('portability', $portability); - } else { - /* Default to the same DB handle for reads. */ - $this->_db = $this->_write_db; - } + ), $this->_params); return true; } diff --git a/framework/Form/Form/Type.php b/framework/Form/Form/Type.php index 713413c5f..98e06d49c 100644 --- a/framework/Form/Form/Type.php +++ b/framework/Form/Form/Type.php @@ -3592,21 +3592,21 @@ class Horde_Form_Type_dblookup extends Horde_Form_Type_enum { function init($dsn, $sql, $prompt = null) { - require_once 'DB.php'; $values = array(); $db = DB::connect($dsn); - if (!is_a($db, 'PEAR_Error')) { + if (!($db instanceof PEAR_Error)) { // Set DB portability options. switch ($db->phptype) { case 'mssql': $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); break; + default: $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); } $col = $db->getCol($sql); - if (!is_a($col, 'PEAR_Error')) { + if (!($col instanceof PEAR_Error)) { $values = array_combine($col, $col); } } diff --git a/framework/Model/lib/Horde/Form.php b/framework/Model/lib/Horde/Form.php index 6eec2319b..89f8d210d 100644 --- a/framework/Model/lib/Horde/Form.php +++ b/framework/Model/lib/Horde/Form.php @@ -3029,18 +3029,20 @@ class Horde_Form_Type_dblookup extends Horde_Form_Type_enum { { $values = array(); $db = DB::connect($dsn); - if (!is_a($db, 'PEAR_Error')) { + if (!($db instanceof PEAR_Error)) { // Set DB portability options. switch ($db->phptype) { case 'mssql': $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); break; + default: $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); + break; } $col = $db->getCol($sql); - if (!is_a($col, 'PEAR_Error')) { + if (!($col instanceof PEAR_Error)) { $values = array_combine($col, $col); } } diff --git a/framework/VFS/lib/VFS/sql.php b/framework/VFS/lib/VFS/sql.php index fdb374f51..1c1163437 100644 --- a/framework/VFS/lib/VFS/sql.php +++ b/framework/VFS/lib/VFS/sql.php @@ -3,28 +3,18 @@ * VFS implementation for PHP's PEAR database abstraction layer. * * Required values for $params:
- * phptype - (string) The database type (ie. 'pgsql', 'mysql', etc.).
+ * db - (DB) A DB object. + * * * Optional values:
  * table - (string) The name of the vfs table in 'database'. Defaults to
- *         'horde_vfs'.
- * - * Required by some database implementations:
- * hostspec - (string) The hostname of the database server.
- * protocol - (string) The communication protocol ('tcp', 'unix', etc.).
- * database - (string) The name of the database.
- * username - (string) The username with which to connect to the database.
- * password - (string) The password associated with 'username'.
- * options - (array) Additional options to pass to the database.
- * tty - (string) The TTY on which to connect to the database.
- * port - (integer) The port on which to connect to the database.
+ * 'horde_vfs'. + * * * Optional values when using separate reading and writing servers, for example * in replication settings:
- * splitread - (boolean) Whether to implement the separation or not.
- * read - (array) Parameters which are different for the read database
- *                connection, currently supported only 'hostspec' and 'port'
- *                parameters.
+ * writedb - (DB) A writable DB object + * * * The table structure for the VFS can be found in data/vfs.sql. * @@ -46,8 +36,10 @@ * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. * - * @author Chuck Hagenbuch - * @package VFS + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package VFS */ class VFS_sql extends VFS { @@ -701,82 +693,21 @@ class VFS_sql extends VFS protected function _connect() { if ($this->_connected) { - return true; + return; } - if (!is_array($this->_params)) { - throw new VFS_Exception('No configuration information specified for SQL VFS.'); - } - - $required = array('phptype'); - foreach ($required as $val) { - if (!isset($this->_params[$val])) { - throw new VFS_Exception(sprintf('Required "%s" not specified in VFS configuration.', $val)); - } + if (!isset($this->_params['db'])) { + throw new VFS_Exception('Required "db" not specified in VFS configuration.'); } $this->_params = array_merge(array( - 'database' => '', - 'hostspec' => '', - 'table' => 'horde_vfs', - 'username' => '' + 'table' => 'horde_vfs' ), $this->_params); - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_write_db = DB::connect( - $this->_params, - array( - 'persistent' => !empty($this->_params['persistent']), - 'ssl' => !empty($this->_params['ssl'] - ) - )); - - if ($this->_write_db instanceof PEAR_Error) { - $this->log($this->_write_db, PEAR_LOG_ERR); - $error = new VFS_Exception($this->_write_db->getMessage()); - $this->_write_db = false; - throw $error; - } - - // Set DB portability options. - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection - * seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = DB::connect( - $params, - array( - 'persistent' => !empty($params['persistent']), - 'ssl' => !empty($params['ssl'] - ) - )); - - if ($this->_db instanceof PEAR_Error) { - throw new VFS_Exception($this->_db->getMessage()); - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - } else { - /* Default to the same DB handle for reads. */ - $this->_db =& $this->_write_db; - } + $this->_db = $this->_params['db']; + $this->_write_db = isset($this->_params['writedb']) + ? $this->_params['writedb'] + : $this->_params['db']; $this->_connected = true; } diff --git a/framework/VFS/lib/VFS/sql_file.php b/framework/VFS/lib/VFS/sql_file.php index 8143a015a..39a3126c5 100644 --- a/framework/VFS/lib/VFS/sql_file.php +++ b/framework/VFS/lib/VFS/sql_file.php @@ -13,7 +13,7 @@ include_once 'VFS/file.php'; * layer and local file system for file storage. * * Required values for $params:
- * phptype - (string) The database type (ie. 'pgsql', 'mysql', etc.).
+ * db - (DB) The DB object.
  * vfsroot - (string) The root directory of where the files should be
  *           actually stored.
* @@ -21,21 +21,11 @@ include_once 'VFS/file.php'; * table - (string) The name of the vfs table in 'database'. Defaults to * 'horde_vfs'. * - * Required by some database implementations:
- * hostspec - (string) The hostname of the database server.
- * protocol - (string) The communication protocol ('tcp', 'unix', etc.).
- * database - (string) The name of the database.
- * username - (string) The username with which to connect to the database.
- * password - (string) The password associated with 'username'.
- * options - (array) Additional options to pass to the database.
- * tty - (string) The TTY on which to connect to the database.
- * port - (integer) The port on which to connect to the database.
+ * The table structure for the VFS can be found in data/vfs.sql. * - * The table structure for the VFS can be found in - * data/vfs.sql. - * - * @author Michael Varghese - * @package VFS + * @author Michael Varghese + * @category Horde + * @package VFS */ class VFS_sql_file extends VFS_file { @@ -624,11 +614,7 @@ class VFS_sql_file extends VFS_file return; } - if (!is_array($this->_params)) { - throw new VFS_Exception('No configuration information specified for SQL-File VFS.'); - } - - $required = array('phptype', 'vfsroot'); + $required = array('db', 'vfsroot'); foreach ($required as $val) { if (!isset($this->_params[$val])) { throw new VFS_Exception(sprintf('Required "%s" not specified in VFS configuration.', $val)); @@ -636,36 +622,10 @@ class VFS_sql_file extends VFS_file } $this->_params = array_merge(array( - 'database' => '', - 'hostspec' => '', 'table' => 'horde_vfs', - 'username' => '' ), $this->_params); - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_db = DB::connect( - $this->_params, - array( - 'persistent' => !empty($this->_params['persistent']), - 'ssl' => !empty($this->_params['ssl'] - ) - )); - if ($this->_db instanceof PEAR_Error) { - $error = new VFS_Exception($this->_db->getMessage()); - $this->_db = false; - throw $error; - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } + $this->_db = $this->_params['db']; } /** diff --git a/hermes/lib/Driver/sql.php b/hermes/lib/Driver/sql.php index df8b16e69..15d8aa52d 100644 --- a/hermes/lib/Driver/sql.php +++ b/hermes/lib/Driver/sql.php @@ -692,44 +692,17 @@ class Hermes_Driver_sql extends Hermes_Driver { /** * Attempts to open a persistent connection to the SQL server. * - * @return boolean True on success; exits (Horde::fatal()) on error. + * @return boolean True on success. + * @throws Horde_Exception */ function _connect() { - if (!$this->_connected) { - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - include_once 'DB.php'; - $this->_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if (is_a($this->_db, 'PEAR_Error')) { - Horde::fatal($this->_db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - $this->_connected = true; + if ($this->_connected) { + return true; } + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'hermes', 'storage'); + return true; } diff --git a/hylax/lib/Storage/sql.php b/hylax/lib/Storage/sql.php index bae0af90a..1eff224b3 100644 --- a/hylax/lib/Storage/sql.php +++ b/hylax/lib/Storage/sql.php @@ -373,37 +373,7 @@ class Hylax_Storage_sql extends Hylax_Storage { function initialise() { - global $registry; - - Horde::assertDriverConfig($this->_params, 'sql', - array('phptype')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if (is_a($this->_db, 'PEAR_Error')) { - Horde::fatal($this->_db, __FILE__, __LINE__); - } - - // Set DB portability options - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'hylax', 'sql'); return true; } diff --git a/ingo/lib/Storage/Sql.php b/ingo/lib/Storage/Sql.php index 5284f7c87..9593297de 100644 --- a/ingo/lib/Storage/Sql.php +++ b/ingo/lib/Storage/Sql.php @@ -3,20 +3,6 @@ * Ingo_Storage_Sql implements the Ingo_Storage API to save Ingo data via * PHP's PEAR database abstraction layer. * - * Required values for $params:
- *   'phptype'  - The database type (e.g. 'pgsql', 'mysql', etc.).
- *   'charset'  - The database's internal charset.
- * - * Required by some database implementations:
- *   'database' - The name of the database.
- *   'hostspec' - The hostname of the database server.
- *   'protocol' - The communication protocol ('tcp', 'unix', etc.).
- *   'username' - The username with which to connect to the database.
- *   'password' - The password associated with 'username'.
- *   'options'  - Additional options to pass to the database.
- *   'tty'      - The TTY on which to connect to the database.
- *   'port'     - The port on which to connect to the database.
- * * The table structure can be created by the scripts/drivers/sql/ingo.sql * script. * @@ -61,64 +47,16 @@ class Ingo_Storage_Sql extends Ingo_Storage */ public function __construct($params = array()) { - $this->_params = $params; - - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - $this->_params['table_rules'] = 'ingo_rules'; - $this->_params['table_lists'] = 'ingo_lists'; - $this->_params['table_vacations'] = 'ingo_vacations'; - $this->_params['table_forwards'] = 'ingo_forwards'; - $this->_params['table_spam'] = 'ingo_spam'; - - /* Connect to the SQL server using the supplied parameters. */ - $this->_write_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']), - 'ssl' => !empty($this->_params['ssl']))); - if (is_a($this->_write_db, 'PEAR_Error')) { - throw new Horde_Exception_Prior($this->_write_db); - } - /* Set DB portability options. */ - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = &DB::connect($params, - array('persistent' => !empty($params['persistent']), - 'ssl' => !empty($params['ssl']))); - if (is_a($this->_db, 'PEAR_Error')) { - throw new Horde_Exception_Prior($this->_db); - } - - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db =& $this->_write_db; - } + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'ingo', 'storage'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'ingo', 'storage'); + + $this->_params = array_merge($params, array( + 'table_rules' => 'ingo_rules', + 'table_lists' => 'ingo_lists', + 'table_vacations' => 'ingo_vacations', + 'table_forwards' => 'ingo_forwards', + 'table_spam' => 'ingo_spam' + )); parent::__construct(); } diff --git a/jonah/lib/Driver/Sql.php b/jonah/lib/Driver/Sql.php index 504f14679..15a6354c4 100644 --- a/jonah/lib/Driver/Sql.php +++ b/jonah/lib/Driver/Sql.php @@ -2,20 +2,6 @@ /** * Jonah storage implementation for PHP's PEAR database abstraction layer. * - * Required values for $params:
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'charset'       The database's internal charset.
- * - * Required by some database implementations:
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'database'      The name of the database.
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.
- * * The table structure can be created by the scripts/db/jonah_news.sql * script. The needed tables are jonah_channels and jonah_stories. * @@ -998,7 +984,7 @@ class Jonah_Driver_Sql extends Jonah_Driver /** * Attempts to open a persistent connection to the SQL server. * - * @return boolean True on success; PEAR_Error on failure. + * @return boolean True on success; PEAR_Error on failure. */ protected function _connect() { @@ -1006,37 +992,14 @@ class Jonah_Driver_Sql extends Jonah_Driver return true; } - Horde::assertDriverConfig($this->_params, 'news', - array('phptype', 'charset'), - 'jonah news SQL'); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - $this->_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if (is_a($this->_db, 'PEAR_Error')) { - return $this->_db; - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); + try { + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'jonah', 'news'); + } catch (Horde_Exception $e) { + return PEAR::raiseError($e->getMessage()); } $this->_connected = true; + return true; } diff --git a/jonah/lib/News/sql.php b/jonah/lib/News/sql.php index 8937990d5..a762e18da 100644 --- a/jonah/lib/News/sql.php +++ b/jonah/lib/News/sql.php @@ -2,20 +2,6 @@ /** * Jonah storage implementation for PHP's PEAR database abstraction layer. * - * Required values for $params:
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'charset'       The database's internal charset.
- * - * Required by some database implementations:
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'database'      The name of the database.
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.
- * * The table structure can be created by the scripts/db/jonah_news.sql * script. The needed tables are jonah_channels and jonah_stories. * @@ -850,7 +836,7 @@ class Jonah_News_sql extends Jonah_News { /** * Attempts to open a persistent connection to the SQL server. * - * @return boolean True on success; PEAR_Error on failure. + * @return boolean True on success; PEAR_Error on failure. */ function _connect() { @@ -858,37 +844,14 @@ class Jonah_News_sql extends Jonah_News { return true; } - Horde::assertDriverConfig($this->_params, 'news', - array('phptype', 'charset'), - 'jonah news SQL'); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - $this->_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if (is_a($this->_db, 'PEAR_Error')) { - return $this->_db; - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); + try { + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'jonah', 'news'); + } catch (Horde_Exception $e) { + return PEAR::raiseError($e->getMessage()); } $this->_connected = true; + return true; } diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index 7070d38fd..b52edc90d 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -882,79 +882,39 @@ class Kronolith_Driver_Sql extends Kronolith_Driver */ public function initialize() { - Horde::assertDriverConfig($this->_params, 'calendar', - array('phptype')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - if (!isset($this->_params['table'])) { - $this->_params['table'] = 'kronolith_events'; - } - - /* Connect to the SQL server using the supplied parameters. */ - $this->_write_db = DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']), - 'ssl' => !empty($this->_params['ssl']))); - $this->handleError($this->_write_db); - $this->_initConn($this->_write_db); - - /* Check if we need to set up the read DB connection - * seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = DB::connect($params, - array('persistent' => !empty($params['persistent']), - 'ssl' => !empty($params['ssl']))); - $this->handleError($this->_db); - $this->_initConn($this->_db); - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db = $this->_write_db; - } - } - - /** - */ - private function _initConn(&$db) - { - // Set DB portability options. - switch ($db->phptype) { - case 'mssql': - $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); + try { + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'kronolith', 'calendar'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'kronolith', 'calendar'); + } catch (Horde_Exception $e) { + throw new Kronolith_Exception($e); } - /* Handle any database specific initialization code to run. */ - switch ($db->dbsyntax) { - case 'oci8': - $query = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"; + foreach (array($this->_db, $this->_write_db) as $db) { + /* Handle any database specific initialization code to run. */ + switch ($db->dbsyntax) { + case 'oci8': + $query = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"; - /* Log the query at a DEBUG log level. */ - Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"', - $GLOBALS['registry']->getAuth(), $query), 'DEBUG'); + /* Log the query at a DEBUG log level. */ + Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"', $GLOBALS['registry']->getAuth(), $query), 'DEBUG'); - $db->query($query); - break; + $db->query($query); + break; - case 'pgsql': - $query = "SET datestyle TO 'iso'"; + case 'pgsql': + $query = "SET datestyle TO 'iso'"; - /* Log the query at a DEBUG log level. */ - Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"', - $GLOBALS['registry']->getAuth(), $query), 'DEBUG'); + /* Log the query at a DEBUG log level. */ + Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"', $GLOBALS['registry']->getAuth(), $query), 'DEBUG'); - $db->query($query); - break; + $db->query($query); + break; + } } + + $this->_params = array_merge(array( + 'table' => 'kronolith_events' + ), $this->_params); } /** diff --git a/kronolith/lib/Geo/Sql.php b/kronolith/lib/Geo/Sql.php index 5b12b92f0..e6e3a0b3c 100644 --- a/kronolith/lib/Geo/Sql.php +++ b/kronolith/lib/Geo/Sql.php @@ -8,9 +8,9 @@ * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Michael J. Rubinsky - * - * @package Kronolith + * @author Michael J. Rubinsky + * @category Horde + * @package Kronolith */ class Kronolith_Geo_Sql extends Kronolith_Geo { @@ -22,61 +22,16 @@ class Kronolith_Geo_Sql extends Kronolith_Geo */ public function initialize() { - Horde::assertDriverConfig($this->_params, 'calendar', array('phptype')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - if (!isset($this->_params['table'])) { - $this->_params['table'] = 'kronolith_events_geo'; - } - - /* Connect to the SQL server using the supplied parameters. */ - $this->_write_db = DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']), - 'ssl' => !empty($this->_params['ssl']))); - if ($this->_write_db instanceof PEAR_Error) { - throw new Kronolith_Exception($this->_write_db); - } - $this->_initConn($this->_write_db); - - /* Check if we need to set up the read DB connection - * seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = DB::connect($params, - array('persistent' => !empty($params['persistent']), - 'ssl' => !empty($params['ssl']))); - if ($this->_db instanceof PEAR_Error) { - throw new Kronolith_Exception($this->_db); - } - $this->_initConn($this->_db); - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db = $this->_write_db; + try { + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'kronolith', 'calendar'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'kronolith', 'calendar'); + } catch (Horde_Exception $e) { + throw new Kronolith_Exception($e); } return true; } - protected function _initConn(&$db) - { - // Set DB portability options. - switch ($db->phptype) { - case 'mssql': - $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - } - /** * Set the location of the specified event _id * diff --git a/kronolith/lib/Storage/sql.php b/kronolith/lib/Storage/sql.php index 5344b4013..ddc14b3b0 100644 --- a/kronolith/lib/Storage/sql.php +++ b/kronolith/lib/Storage/sql.php @@ -50,53 +50,11 @@ class Kronolith_Storage_sql extends Kronolith_Storage */ public function initialize() { - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype'), - 'kronolith storage SQL'); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - include_once 'DB.php'; - $this->_write_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']), - 'ssl' => !empty($this->_params['ssl']))); - $this->handleError($this->_write_db); - $this->_initConn($this->_write_db); - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = &DB::connect($params, - array('persistent' => !empty($params['persistent']), - 'ssl' => !empty($params['ssl']))); - $this->handleError($this->_db); - $this->_initConn($this->_db); - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db =& $this->_write_db; - } - } - - /** - */ - private function _initConn(&$db) - { - // Set DB portability options. - switch ($db->phptype) { - case 'mssql': - $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); + try { + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'kronolith', 'storage'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'kronolith', 'storage'); + } catch (Horde_Exception $e) { + throw new Kronolith_Exception($e); } } diff --git a/luxor/lib/Driver/sql.php b/luxor/lib/Driver/sql.php index c75cbdda8..a7641690f 100644 --- a/luxor/lib/Driver/sql.php +++ b/luxor/lib/Driver/sql.php @@ -2,20 +2,6 @@ /** * Luxor storage implementation for PHP's PEAR database abstraction layer. * - * Required values for $params:
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'charset'       The database's internal charset.
- * - * Required by some database implementations:
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'database'      The name of the database.
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.
- * * The table structure can be created by the scripts/drivers/luxor.sql * script. * @@ -521,40 +507,12 @@ class Luxor_Driver_sql extends Luxor_Driver { /** * Attempts to open a persistent connection to the SQL server. * - * @return boolean True on success; exits (Horde::fatal()) on error. + * @return boolean True on success. */ function _connect() { if (!$this->_connected) { - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - $this->_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if (is_a($this->_db, 'PEAR_Error')) { - Horde::fatal($this->_db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'luxor', 'storage'); $this->_connected = true; } diff --git a/mnemo/lib/Driver/sql.php b/mnemo/lib/Driver/sql.php index 637f4a615..cf58f79bb 100644 --- a/mnemo/lib/Driver/sql.php +++ b/mnemo/lib/Driver/sql.php @@ -3,24 +3,6 @@ * Mnemo storage implementation for PHP's PEAR database abstraction * layer. * - * Required parameters:
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'charset'       The database's internal charset.
- * - * Optional values:
- *      'table'         The name of the memos table in 'database'. Defaults
- *                      to 'mnemo_memos'
- * - * Required by some database implementations:
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'database'      The name of the database.
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.
- * * The table structure is defined in scripts/drivers/mnemo_memos.sql. * * $Horde: mnemo/lib/Driver/sql.php,v 1.53 2009/07/09 08:18:32 slusarz Exp $ @@ -73,68 +55,16 @@ class Mnemo_Driver_sql extends Mnemo_Driver { /** * Attempts to open a connection to the SQL server. * - * @return boolean True on success, PEAR_Error on failure. + * @return boolean True on success. */ function initialize() { - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - if (!isset($this->_params['table'])) { - $this->_params['table'] = 'mnemo_memos'; - } + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'mnemo', 'storage'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'mnemo', 'storage'); - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_write_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']), - 'ssl' => !empty($this->_params['ssl']))); - if (is_a($this->_write_db, 'PEAR_Error')) { - Horde::fatal($this->_write_db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection - * seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = &DB::connect($params, - array('persistent' => !empty($params['persistent']), - 'ssl' => !empty($params['ssl']))); - if (is_a($this->_db, 'PEAR_Error')) { - Horde::fatal($this->_db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - } else { - /* Default to the same DB handle for reads. */ - $this->_db =& $this->_write_db; - } + $this->_params = array_merge(array( + 'table' => 'mnemo_memos' + ), $this->_params); return true; } diff --git a/news/lib/Driver/sql.php b/news/lib/Driver/sql.php index 6070a5c08..08bb57236 100644 --- a/news/lib/Driver/sql.php +++ b/news/lib/Driver/sql.php @@ -376,62 +376,13 @@ class News_Driver_sql extends News_Driver { */ private function _connect() { - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset')); + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'news', 'storage'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'news', 'storage'); - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } if (isset($this->_params['prefix'])) { $this->prefix = $this->_params['prefix']; } - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->write_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if ($this->write_db instanceof PEAR_Error) { - throw new Horde_Exception_Prior($this->write_db); - } - - // Set DB portability options. - switch ($this->write_db->phptype) { - case 'mssql': - $this->write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->db = &DB::connect($params, - array('persistent' => !empty($params['persistent']))); - if ($this->db instanceof PEAR_Error) { - throw new Horde_Exception_Prior($this->db); - } - - // Set DB portability options. - switch ($this->db->phptype) { - case 'mssql': - $this->db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - } else { - /* Default to the same DB handle for the writer too. */ - $this->db =& $this->write_db; - } - return true; } diff --git a/operator/lib/Driver/asterisksql.php b/operator/lib/Driver/asterisksql.php index 55dbb417a..068bdb3a4 100644 --- a/operator/lib/Driver/asterisksql.php +++ b/operator/lib/Driver/asterisksql.php @@ -2,21 +2,6 @@ /** * Operator storage implementation for PHP's PEAR database abstraction layer. * - * Required values for $params:
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'table'         The name of the foo table in 'database'.
- *      'charset'       The database's internal charset.
- * - * Required by some database implementations:
- *      'database'      The name of the database.
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.
- * * The table structure can be created by the scripts/sql/operator_foo.sql * script. * @@ -345,7 +330,8 @@ class Operator_Driver_asterisksql extends Operator_Driver { /** * Attempts to open a connection to the SQL server. * - * @return boolean True on success; exits (Horde::fatal()) on error. + * @return boolean True on success. + * @throws Horde_Exception */ protected function _connect() { @@ -353,60 +339,8 @@ class Operator_Driver_asterisksql extends Operator_Driver { return true; } - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset', 'table')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->_write_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if (is_a($this->_write_db, 'PEAR_Error')) { - Horde::fatal($this->_write_db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = &DB::connect($params, - array('persistent' => !empty($params['persistent']))); - if (is_a($this->_db, 'PEAR_Error')) { - Horde::fatal($this->_db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db =& $this->_write_db; - } - - $this->_connected = true; + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'operator', 'storage'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'operator', 'storage'); return true; } diff --git a/pastie/lib/Driver/Sql.php b/pastie/lib/Driver/Sql.php index fa517a225..2d176b642 100644 --- a/pastie/lib/Driver/Sql.php +++ b/pastie/lib/Driver/Sql.php @@ -238,65 +238,11 @@ class Pastie_Driver_Sql extends Pastie_Driver */ protected function _connect() { - if ($this->_connected) { - return; - } - - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - $this->_write_db = DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if ($this->_write_db instanceof PEAR_Error) { - throw new Horde_Exception_Prior($this->_write_db); - } - - // Set DB portability options. - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = DB::connect($params, - array('persistent' => !empty($params['persistent']))); - if ($this->_db instanceof PEAR_Error) { - throw new Horde_Exception_Prior($this->_db); - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db = $this->_write_db; + if (!$this->_connected) { + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'pastie', 'storage'); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'pastie', 'storage'); + $this->_connected = true; } - - $this->_connected = true; } /** diff --git a/shout/lib/Driver/Sql.php b/shout/lib/Driver/Sql.php index 5448b6d81..d21783f39 100644 --- a/shout/lib/Driver/Sql.php +++ b/shout/lib/Driver/Sql.php @@ -718,65 +718,16 @@ class Shout_Driver_Sql extends Shout_Driver */ protected function _connect() { - if ($this->_connected) { - return; - } - - Horde::assertDriverConfig($this->_params, $this->_params['class'], - array('phptype', 'charset')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - - /* Connect to the SQL server using the supplied parameters. */ - $this->_write_db = DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if ($this->_write_db instanceof PEAR_Error) { - throw new Shout_Exception($this->_write_db); - } - - // Set DB portability options. - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->_db = DB::connect($params, - array('persistent' => !empty($params['persistent']))); - if ($this->_db instanceof PEAR_Error) { - throw Shout_Exception($this->_db); + if (!$this->_connected) { + try { + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'shout', $this->_params['class']); + $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'shout', $this->_params['class']); + } catch (Horde_Exception $e) { + throw new Shout_Exception($e); } - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - } else { - /* Default to the same DB handle for the writer too. */ - $this->_db = $this->_write_db; + $this->_connected = true; } - - $this->_connected = true; } /** diff --git a/skoli/lib/Driver/sql.php b/skoli/lib/Driver/sql.php index fb7393f38..a63cfa8e4 100644 --- a/skoli/lib/Driver/sql.php +++ b/skoli/lib/Driver/sql.php @@ -2,27 +2,6 @@ /** * Skoli storage implementation for PHP's PEAR database abstraction layer. * - * Required parameters:
- *   'phptype'      The database type (e.g. 'pgsql', 'mysql', etc.).
- *   'charset'      The database's internal charset.
- * - * Required by some database implementations:
- *   'hostspec'     The hostname of the database server.
- *   'protocol'     The communication protocol ('tcp', 'unix', etc.).
- *   'database'     The name of the database.
- *   'username'     The username with which to connect to the database.
- *   'password'     The password associated with 'username'.
- *   'options'      Additional options to pass to the database.
- *   'tty'          The TTY on which to connect to the database.
- *   'port'         The port on which to connect to the database.
- * - * Optional values when using separate reading and writing servers, for example - * in replication settings:
- *   'splitread'   Boolean, whether to implement the separation or not.
- *   'read'        Array containing the parameters which are different for
- *                 the read database connection, currently supported
- *                 only 'hostspec' and 'port' parameters.
- * * Optional parameters:
  *   'objects_table'            The name of the objects table in 'database'.
  *                              Default is 'skoli_objects'.
@@ -75,67 +54,18 @@ class Skoli_Driver_sql extends Skoli_Driver {
      */
     function initialize()
     {
-        Horde::assertDriverConfig($this->_params, 'storage',
-            array('phptype', 'charset'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-        if (!isset($this->_params['objects_table'])) {
-            $this->_params['objects_table'] = 'skoli_objects';
-        }
-        if (!isset($this->_params['object_attributes_table'])) {
-            $this->_params['object_attributes_table'] = 'skoli_object_attributes';
-        }
-        if (!isset($this->_params['students_table'])) {
-            $this->_params['students_table'] = 'skoli_classes_students';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        $this->_write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_write_db, 'PEAR_Error')) {
-            return $this->_write_db;
-        }
-
-        /* Set DB portability options. */
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection
-         * seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                return $this->_db;
-            }
-
-            /* Set DB portability options. */
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db =& $this->_write_db;
-        }
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'skoli', 'storage');
+            $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'skoli', 'storage');
+        } catch (Horde_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
+        }
+
+        $this->_params = array_merge(array(
+            'objects_table' => 'skoli_objects',
+            'object_attributes_table' => 'skoli_object_attributes',
+            'students_table' => 'skoli_classes_students'
+        ), $this->_params);
 
         return true;
     }
diff --git a/turba/scripts/import_squirrelmail_sql_abook.php b/turba/scripts/import_squirrelmail_sql_abook.php
index f6d1de72f..dd3668337 100755
--- a/turba/scripts/import_squirrelmail_sql_abook.php
+++ b/turba/scripts/import_squirrelmail_sql_abook.php
@@ -31,7 +31,7 @@ $dsn = $argv[1];
 
 // Connect to database.
 $db = DB::connect($dsn);
-if (is_a($db, 'PEAR_Error')) {
+if ($db instanceof PEAR_Error) {
     $cli->fatal($db->toString());
 }
 
diff --git a/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php b/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php
index e00b02136..10b1645a4 100755
--- a/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php
+++ b/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php
@@ -39,22 +39,10 @@ $do_email = true;
 require_once dirname(__FILE__) . '/../../lib/Application.php';
 Horde_Registry::appInit('turba', array('authentication' => 'none', 'cli' => true));
 
-/* Grab what we need to steal the DB config */
-require_once HORDE_BASE . '/config/conf.php';
 require_once 'Horde/Form.php';
 
-$config = $GLOBALS['conf']['sql'];
-if (!is_null($db_user)) {
-    $config['username'] = $db_user;
-}
-if (!is_null($db_pass)) {
-    $config['password'] = $db_pass;
-}
-unset($config['charset']);
-$db = DB::connect($config);
-if (is_a($db, 'PEAR_Error')) {
-    throw new Horde_Exception($db);
-}
+$db = $injector->getInstance('Horde_Db_Pear')->getDb();
+
 if (!$for_real) {
     $cli->message('No changes will done to the existing data. Please read the comments in the code, then set the $for_real flag to true before running.', 'cli.message');
 }
@@ -97,15 +85,18 @@ $queries = array(
     'CREATE INDEX turba_firstname_idx ON ' . $db_table . ' (object_firstname)',
     'CREATE INDEX turba_lastname_idx ON ' . $db_table . ' (object_lastname)',
 );
+
 switch ($config['phptype']) {
 case 'mssql':
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_photo VARBINARY(MAX)';
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_logo VARBINARY(MAX)';
     break;
+
 case 'pgsql':
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_photo TEXT';
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_logo TEXT';
     break;
+
 default:
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_photo BLOB';
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_logo BLOB';
diff --git a/vilma/lib/Driver/qmailldap.php b/vilma/lib/Driver/qmailldap.php
index fe25747c0..85ca5eba2 100644
--- a/vilma/lib/Driver/qmailldap.php
+++ b/vilma/lib/Driver/qmailldap.php
@@ -1264,35 +1264,10 @@ class Vilma_Driver_qmailldap extends Vilma_Driver {
     {
         global $registry;
 
-        Horde::assertDriverConfig($this->_sqlparams, 'storage',
-                                  array('phptype'));
-
-        if (!isset($this->_sqlparams['database'])) {
-            $this->_sqlparams['database'] = '';
-        }
-        if (!isset($this->_sqlparams['username'])) {
-            $this->_sqlparams['username'] = '';
-        }
-        if (!isset($this->_sqlparams['hostspec'])) {
-            $this->_sqlparams['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_db = &DB::connect($this->_sqlparams,
-                                  array('persistent' => !empty($this->_sqlparams['persistent'])));
-        if (is_a($this->_db, 'PEAR_Error')) {
-            return $this->_db;
-        }
-
-        // Set DB portability options.
-        switch ($this->_db->phptype) {
-        case 'mssql':
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-
-        default:
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'vilma', 'storage');
+        } catch (Horde_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
         }
     }
 }
diff --git a/vilma/lib/Driver/sql.php b/vilma/lib/Driver/sql.php
index 4913b124c..fc598595b 100644
--- a/vilma/lib/Driver/sql.php
+++ b/vilma/lib/Driver/sql.php
@@ -588,19 +588,10 @@ class Vilma_Driver_sql extends Vilma_Driver {
      */
     function initialise()
     {
-        global $registry;
-
-        Horde::assertDriverConfig($this->_params, 'storage',
-            array('phptype'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'vilma', 'storage');
+        } catch (Horde_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
         }
 
         /* Use default table names if these are not set. */
@@ -614,24 +605,6 @@ class Vilma_Driver_sql extends Vilma_Driver {
             $this->_params['tables']['virtuals'] = 'vilma_virtuals';
         }
 
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_db = &DB::connect($this->_params,
-                                  array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_db, 'PEAR_Error')) {
-            return $this->_db;
-        }
-
-        // Set DB portability options.
-        switch ($this->_db->phptype) {
-        case 'mssql':
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-
-        default:
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
         return true;
     }
 
diff --git a/whups/lib/Driver/sql.php b/whups/lib/Driver/sql.php
index e36acac48..b97799c92 100644
--- a/whups/lib/Driver/sql.php
+++ b/whups/lib/Driver/sql.php
@@ -2874,58 +2874,8 @@ class Whups_Driver_sql extends Whups_Driver {
      */
     function initialise()
     {
-        Horde::assertDriverConfig($this->_params, 'tickets',
-            array('phptype'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_write_db, 'PEAR_Error')) {
-            Horde::fatal($this->_write_db, __FILE__, __LINE__);
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection
-         * seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                Horde::fatal($this->_db, __FILE__, __LINE__);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-        } else {
-            /* Default to the same DB handle for reads. */
-            $this->_db =& $this->_write_db;
-        }
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'whups', 'tickets');
+        $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'whups', 'tickets');
 
         return true;
     }
diff --git a/whups/scripts/bugzilla-import.php b/whups/scripts/bugzilla-import.php
index 3d345fc15..e56bcfdfb 100755
--- a/whups/scripts/bugzilla-import.php
+++ b/whups/scripts/bugzilla-import.php
@@ -53,7 +53,7 @@ function info($text)
 
 /* Connect to the Bugzilla database. */
 $bugzilla = DB::connect($BUGZILLA_DSN);
-if (is_a($bugzilla, 'PEAR_Error')) {
+if ($bugzilla instanceof PEAR_Error) {
     error('Failed to connect to Bugzilla database', $bugzilla);
     exit;
 }
diff --git a/wicked/lib/Driver/sql.php b/wicked/lib/Driver/sql.php
index f3373fa3d..652e932cb 100644
--- a/wicked/lib/Driver/sql.php
+++ b/wicked/lib/Driver/sql.php
@@ -7,21 +7,6 @@
  * Wicked storage implementation for PHP's PEAR database abstraction
  * layer.
  *
- * Required values for $params:
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'database'      The name of the database.
- *      'table'         The name of the tasks table in 'database'.
- *      'charset'       The database's internal charset.
- * - * Required by some database implementations:
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.
- * * The table structure can be created by the scripts/drivers/wicked_foo.sql * script. * @@ -957,47 +942,18 @@ class Wicked_Driver_sql extends Wicked_Driver { */ function connect() { - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - if (!isset($this->_params['table'])) { - $this->_params['table'] = 'wicked_pages'; - } - if (!isset($this->_params['historytable'])) { - $this->_params['historytable'] = 'wicked_history'; + try { + $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'wicked', 'storage'); + } catch (Horde_Exception $e) { + return PEAR::raiseError($e->getMessage()); } - if (!isset($this->_params['attachmenttable'])) { - $this->_params['attachmenttable'] = 'wicked_attachments'; - } - if (!isset($this->_params['attachmenthistorytable'])) { - $this->_params['attachmenthistorytable'] = 'wicked_attachment_history'; - } - - /* Connect to the SQL server using the supplied parameters. */ - $this->_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if (is_a($this->_db, 'PEAR_Error')) { - return $this->_db; - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } + $this->_params = array_merge(array( + 'table' => 'wicked_pages', + 'historytable' => 'wicked_history', + 'attachmenttable' => 'wicked_attachments', + 'attachmenthistorytable' => 'wicked_attachment_history' + ), $this->_params); return true; }