1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5
* An open source application development framework for PHP 5.1.6 or newer
8
* @author ExpressionEngine Dev Team
9
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10
* @license http://codeigniter.com/user_guide/license.html
11
* @link http://codeigniter.com
16
// ------------------------------------------------------------------------
19
* Initialize the database
22
* @author ExpressionEngine Dev Team
23
* @link http://codeigniter.com/user_guide/database/
25
* @param bool Determines if active record should be used or not
27
function &DB($params = '', $active_record_override = NULL)
29
// Load the DB config file if a DSN string wasn't passed
30
if (is_string($params) AND strpos($params, '://') === FALSE)
32
// Is the config file in the environment folder?
33
if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
35
if ( ! file_exists($file_path = APPPATH.'config/database.php'))
37
show_error('The configuration file database.php does not exist.');
43
if ( ! isset($db) OR count($db) == 0)
45
show_error('No database connection settings were found in the database config file.');
50
$active_group = $params;
53
if ( ! isset($active_group) OR ! isset($db[$active_group]))
55
show_error('You have specified an invalid database connection group.');
58
$params = $db[$active_group];
60
elseif (is_string($params))
63
/* parse the URL from the DSN string
64
* Database settings can be passed as discreet
65
* parameters or as a data source name in the first
66
* parameter. DSNs must have this prototype:
67
* $dsn = 'driver://username:password@hostname/database';
70
if (($dns = @parse_url($params)) === FALSE)
72
show_error('Invalid DB Connection String');
76
'dbdriver' => $dns['scheme'],
77
'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '',
78
'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '',
79
'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '',
80
'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : ''
83
// were additional config items set?
84
if (isset($dns['query']))
86
parse_str($dns['query'], $extra);
88
foreach ($extra as $key => $val)
91
if (strtoupper($val) == "TRUE")
95
elseif (strtoupper($val) == "FALSE")
100
$params[$key] = $val;
105
// No DB specified yet? Beat them senseless...
106
if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '')
108
show_error('You have not selected a database type to connect to.');
111
// Load the DB classes. Note: Since the active record class is optional
112
// we need to dynamically create a class that extends proper parent class
113
// based on whether we're using the active record class or not.
114
// Kudos to Paul for discovering this clever use of eval()
116
if ($active_record_override !== NULL)
118
$active_record = $active_record_override;
121
require_once(BASEPATH.'database/DB_driver.php');
123
if ( ! isset($active_record) OR $active_record == TRUE)
125
require_once(BASEPATH.'database/DB_active_rec.php');
127
if ( ! class_exists('CI_DB'))
129
eval('class CI_DB extends CI_DB_active_record { }');
134
if ( ! class_exists('CI_DB'))
136
eval('class CI_DB extends CI_DB_driver { }');
140
require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php');
142
// Instantiate the DB adapter
143
$driver = 'CI_DB_'.$params['dbdriver'].'_driver';
144
$DB = new $driver($params);
146
if ($DB->autoinit == TRUE)
151
if (isset($params['stricton']) && $params['stricton'] == TRUE)
153
$DB->query('SET SESSION sql_mode="STRICT_ALL_TABLES"');
161
/* End of file DB.php */
162
/* Location: ./system/database/DB.php */
b'\\ No newline at end of file'