MY_Loader::database PHP Method

database() public method

Database Loader
public database ( mixed $params = '', boolean $return = FALSE, boolean $query_builder = NULL ) : object | boolean
$params mixed Database configuration options
$return boolean Whether to return the database object
$query_builder boolean Whether to enable Query Builder (overrides the configuration setting)
return object | boolean Database object if $return is set to TRUE, FALSE on failure, CI_Loader instance in any other case
    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;
    }