summaryrefslogtreecommitdiffstats
path: root/system/database/DB.php
diff options
context:
space:
mode:
authorEric Roberts <eric@cryode.com>2012-04-15 00:49:21 +0200
committerEric Roberts <eric@cryode.com>2012-04-15 00:49:21 +0200
commit8cefb3ff51de4f023753c0146eb16950f48601a9 (patch)
treeed868ec7a795fcf1fe97efc5642d26dc1d1faefe /system/database/DB.php
parent0760a48d431fb9ab85f2a0ca9af63aa131e29520 (diff)
parent0f2211711deceb74157d6811116acc0376d3157d (diff)
Merge branch 'develop' of https://github.com/EllisLab/CodeIgniter into feature/form_error_msgs
Conflicts: system/language/english/form_validation_lang.php
Diffstat (limited to 'system/database/DB.php')
-rwxr-xr-xsystem/database/DB.php42
1 files changed, 22 insertions, 20 deletions
diff --git a/system/database/DB.php b/system/database/DB.php
index ed6afd7ed..0d81e40d3 100755
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -37,11 +37,11 @@
function &DB($params = '', $active_record_override = NULL)
{
// Load the DB config file if a DSN string wasn't passed
- if (is_string($params) AND strpos($params, '://') === FALSE)
+ if (is_string($params) && strpos($params, '://') === FALSE)
{
// Is the config file in the environment folder?
if (( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
- AND ! file_exists($file_path = APPPATH.'config/database.php'))
+ && ! file_exists($file_path = APPPATH.'config/database.php'))
{
show_error('The configuration file database.php does not exist.');
}
@@ -74,33 +74,30 @@ function &DB($params = '', $active_record_override = NULL)
* parameter. DSNs must have this prototype:
* $dsn = 'driver://username:password@hostname/database';
*/
- if (($dns = @parse_url($params)) === FALSE)
+ if (($dsn = @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['path'], 1)) : ''
+ 'dbdriver' => $dsn['scheme'],
+ 'hostname' => isset($dsn['host']) ? rawurldecode($dsn['host']) : '',
+ 'port' => isset($dsn['port']) ? rawurldecode($dsn['port']) : '',
+ 'username' => isset($dsn['user']) ? rawurldecode($dsn['user']) : '',
+ 'password' => isset($dsn['pass']) ? rawurldecode($dsn['pass']) : '',
+ 'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : ''
);
// were additional config items set?
- if (isset($dns['query']))
+ if (isset($dsn['query']))
{
- parse_str($dns['query'], $extra);
+ parse_str($dsn['query'], $extra);
+
foreach ($extra as $key => $val)
{
- // booleans please
- if (strtoupper($val) === 'TRUE')
- {
- $val = TRUE;
- }
- elseif (strtoupper($val) === 'FALSE')
+ if (is_string($val) && in_array(strtoupper($val), array('TRUE', 'FALSE', 'NULL')))
{
- $val = FALSE;
+ $val = var_export($val);
}
$params[$key] = $val;
@@ -137,7 +134,12 @@ function &DB($params = '', $active_record_override = NULL)
class CI_DB extends CI_DB_driver { }
}
- require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php');
+ // Load the DB driver
+ $driver_file = BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php';
+
+ if ( ! file_exists($driver_file)) show_error('Invalid DB driver');
+
+ require_once($driver_file);
// Instantiate the DB adapter
$driver = 'CI_DB_'.$params['dbdriver'].'_driver';
@@ -157,4 +159,4 @@ function &DB($params = '', $active_record_override = NULL)
}
/* End of file DB.php */
-/* Location: ./system/database/DB.php */
+/* Location: ./system/database/DB.php */ \ No newline at end of file