From 7dd3838f188f35d63a30c30b435fbb7f2e2d3d7e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Feb 2008 04:52:58 +0000 Subject: fixed bug #3419, moved DSN parsing to DB.php so the driver could properly be set to instantiate the correct db driver class. --- system/database/DB.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'system/database/DB.php') diff --git a/system/database/DB.php b/system/database/DB.php index 078f1ef0f..c3e7722d3 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -46,6 +46,29 @@ function &DB($params = '', $active_record_override = FALSE) $params = $db[$active_group]; } + else + { + + /* parse the URL from the DSN string + * Database settings can be passed as discreet + * parameters or as a data source name in the first + * parameter. DSNs must have this prototype: + * $dsn = 'driver://username:password@hostname/database'; + */ + + if (($dns = @parse_url($params)) === FALSE) + { + show_error('Invalid DB Connection String'); + } + + $params = array( + 'dbdriver' => $dns['scheme'], + 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', + 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '', + 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', + 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['host'], 1)) : '' + ); + } // No DB specified yet? Beat them senseless... if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') -- cgit v1.2.3-24-g4f1b