public function database($params = '', $return = FALSE, $query_builder = NULL)
{
// Grab the super object
$CI =& get_instance();
// Do we even need to load the database class?
if ($return === FALSE && $query_builder === NULL && isset($CI->db) && is_object($CI->db) && !empty($CI->db->conn_id)) {
if ($this->_ci_is_inside_module and isset($CI->db)) {
$module_class_name = $this->_ci_module_class;
$CI->{$module_class_name}->db =& $CI->db;
}
return FALSE;
}
require_once BASEPATH . 'database/DB.php';
if ($return === TRUE) {
return DB($params, $query_builder);
}
// Initialize the db variable. Needed to prevent
// reference errors with some configurations
$CI->db = '';
// Load the DB class
$CI->db =& DB($params, $query_builder);
if ($this->_ci_is_inside_module) {
$module_class_name = $this->_ci_module_class;
$CI->{$module_class_name}->db =& $CI->db;
}
return $this;
}