Welcome Guest, Not a member yet? Register   Sign In
Replacing Core Classes Note needed


Maybe it is a good idea to have a note added to the documentation regarding the replacement/extention of core Database classes.


It is misleading as you would now expect it to be possible to replace/extend Database classes

There is a note where it is appropriate: https://www.codeigniter.com/userguide3/g...aries.html

Core classes are the ones located under system/core/, which the DB libs are not.

I knew I had seen it somewhere, just couldn't remenber where

Adding that same note on this page can't hurt


Seeing as DB libs are also not located in ./system/libraries/

You can extend the core DB libraries if you wish.


    /* overloaded methods */

    public function database( $params = '', $return = false, $query_builder = null ) {
        $ci =& get_instance( );

        if ( $return === false && $query_builder === null && isset( $ci->db ) && is_object( $ci->db ) && !empty( $ci->db->conn_id) ) {
            return false;

        require_once( BASEPATH . 'database/DB.php' );

        $db =& DB( $params, $query_builder );

        $driver = config_item( 'subclass_prefix' ) . 'DB_' . $db->dbdriver . '_driver';
        $file = APPPATH . 'libraries/' . $driver . '.php';

        if ( file_exists( $file ) === true && is_file( $file ) === true ) {
            require_once( $file );

            $dbo = new $driver( get_object_vars( $db ) );
            $db = & $dbo;

        if ( $return === true ) {
            return $db;

        $ci->db = '';
        $ci->db = $db;

        return $this;


<?php if ( !defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );

class MY_DB_mysqli_driver extends CI_DB_mysqli_driver {


(This post was last modified: 07-20-2017, 06:25 AM by Martin7483.)

But you can't do that by default. You first need to extend the Loader

And when extending the Loader, or any other class, all you need to do is create a MY_xxxxx.php variant of the file and store it in the correct directory

(This post was last modified: 07-20-2017, 12:58 PM by spjonez.)

(07-20-2017, 06:23 AM)Martin7483 Wrote: But you can't do that by default. You first need to extend the Loader

Correct, the documentation states this Narf linked where above. That doesn't mean you can't only that it isn't available out of the box. The code I posted will allow you to extend them without modifying any core files.

Theme © iAndrew 2016 - Forum software by © MyBB