Skip to content

Instantly share code, notes, and snippets.

@chonthu
Created February 23, 2012 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chonthu/1893490 to your computer and use it in GitHub Desktop.
Save chonthu/1893490 to your computer and use it in GitHub Desktop.
on_duplicate_update 6
class MY_Loader extends CI_Loader {
/**
* Database Loader
*
* @access public
* @param string the DB credentials
* @param bool whether to return the DB object
* @param bool whether to enable active record (this allows us to override the config setting)
* @return object
*/
function database($params = '', $return = FALSE, $active_record = NULL) {
// Grab the super object
$CI =& get_instance();
// Do we even need to load the database class?
if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db)) {
return FALSE;
}
require_once(BASEPATH.'database/DB'.EXT);
// Load the DB class
$db =& DB($params, $active_record);
$my_driver = config_item('subclass_prefix').'DB_'.$db->dbdriver.'_driver';
$my_driver_file = APPPATH.'core/'.$my_driver.EXT;
if (file_exists($my_driver_file)) {
require_once($my_driver_file);
$db = new $my_driver(get_object_vars($db));
}
if ($return === TRUE) {
return $db;
}
// Initialize the db variable. Needed to prevent
// reference errors with some configurations
$CI->db = '';
$CI->db = $db;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment