summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2008-02-13 05:52:58 +0100
committerDerek Jones <derek.jones@ellislab.com>2008-02-13 05:52:58 +0100
commit7dd3838f188f35d63a30c30b435fbb7f2e2d3d7e (patch)
tree5d7545439c0c5a7159368f30fd86905a27eaa8c8
parent5b4d53271a841c60e43d64f4b6b3c32794b41ac7 (diff)
fixed bug #3419, moved DSN parsing to DB.php so the driver could properly be set to instantiate the correct db driver class.
-rw-r--r--system/database/DB.php23
-rw-r--r--system/database/DB_driver.php25
-rw-r--r--user_guide/changelog.html1
3 files changed, 25 insertions, 24 deletions
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'] == '')
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 6b3a74b94..b1013178e 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -70,12 +70,7 @@ class CI_DB_driver {
* Constructor. Accepts one parameter containing the database
* connection settings.
*
- * 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';
- *
- * @param mixed. Can be an array or a DSN string
+ * @param array
*/
function CI_DB_driver($params)
{
@@ -86,24 +81,6 @@ class CI_DB_driver {
$this->$key = $val;
}
}
- elseif (strpos($params, '://'))
- {
- if (FALSE === ($dsn = @parse_url($params)))
- {
- log_message('error', 'Invalid DB Connection String');
-
- if ($this->db_debug)
- {
- return $this->display_error('db_invalid_connection_str');
- }
- return FALSE;
- }
-
- $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']);
- $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']);
- $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']);
- $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1));
- }
log_message('debug', 'Database Driver Class Initialized');
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 5279715f0..4075e64e1 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -95,6 +95,7 @@ Change Log
<li>Fixed a bug in query binding (#3402).</li>
<li>Changed order of SQL keywords in the Profiler $highlight array so OR would not be highlighted before ORDER BY</li>
<li>Fixed a bug (#3404) where the MySQLi driver was testing if $this->conn_id was a resource instead of an object.</li>
+ <li>Fixed a bug (#3419) connecting to a database via a DSN string.</li>
<li>Fixed a bug (#3445) where the routed segment array was not re-indexed to begin with 1 when the default controller is used.</li>
<li>Fixed assorted user guide typos.</li>
</ul>