Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
| 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
| 8 | * @author Rick Ellis
|
| 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
| 10 | * @license http://www.codeignitor.com/user_guide/license.html
|
| 11 | * @link http://www.codeigniter.com
|
| 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * Initialize the database
|
| 20 | *
|
| 21 | * @category Database
|
| 22 | * @author Rick Ellis
|
| 23 | * @link http://www.codeigniter.com/user_guide/database/
|
| 24 | */
|
| 25 | function &DB($params = '', $active_record = FALSE)
|
| 26 | {
|
| 27 | // Load the DB config file if a DSN string wasn't passed
|
| 28 | if (is_string($params) AND strpos($params, '://') === FALSE)
|
| 29 | {
|
| 30 | include(APPPATH.'config/database'.EXT);
|
| 31 |
|
| 32 | $group = ($params == '') ? $active_group : $params;
|
| 33 |
|
| 34 | if ( ! isset($db[$group]))
|
| 35 | {
|
| 36 | show_error('You have specified an invalid database connection group: '.$group);
|
| 37 | }
|
| 38 |
|
| 39 | $params = $db[$group];
|
| 40 | }
|
| 41 |
|
| 42 | // No DB specified yet? Beat them senseless...
|
| 43 | if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '')
|
| 44 | {
|
| 45 | show_error('You have not selected a database type to connect to.');
|
| 46 | }
|
| 47 |
|
| 48 | // Load the DB classes. Note: Since the active record class is optional
|
| 49 | // we need to dynamically create a class that extends proper parent class
|
| 50 | // based on whether we're using the active record class or not.
|
| 51 | // Kudos to Paul for discovering this clever use of eval()
|
| 52 |
|
| 53 | if ($active_record == TRUE)
|
| 54 | {
|
| 55 | $params['active_r'] = TRUE;
|
| 56 | }
|
| 57 |
|
| 58 | require_once(BASEPATH.'database/DB_driver'.EXT);
|
| 59 |
|
| 60 | if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE)
|
| 61 | {
|
| 62 | require_once(BASEPATH.'database/DB_active_rec'.EXT);
|
| 63 |
|
| 64 | if ( ! class_exists('CI_DB'))
|
| 65 | {
|
| 66 | eval('class CI_DB extends CI_DB_active_record { }');
|
| 67 | }
|
| 68 | }
|
| 69 | else
|
| 70 | {
|
| 71 | if ( ! class_exists('CI_DB'))
|
| 72 | {
|
| 73 | eval('class CI_DB extends CI_DB_driver { }');
|
| 74 | }
|
| 75 | }
|
| 76 |
|
| 77 | require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT);
|
| 78 |
|
| 79 | // Instantiate the DB adapter
|
| 80 | $driver = 'CI_DB_'.$params['dbdriver'].'_driver';
|
| 81 | $DB =& new $driver($params);
|
| 82 | return $DB;
|
| 83 | }
|
| 84 |
|
| 85 |
|
admin | 61c5717 | 2006-10-06 17:29:24 +0000 | [diff] [blame] | 86 | ?> |