4

I'm using codeigniter 2.0++ or specifically 3.0-dev. The thing is I have multiple database connection and the profiler only shows query from the default connection $this->db.

class table_m extends CI_Model
{

    function __construct()
    {
        parent :: __construct(); 
        $this->db2 = $this->load->database('production', TRUE);
    }

    function sel_pameran($ukmper=NULL)
    {
        $sql = "SELECT * from table1";

        $query = $this->db2->query($sql);
        return $query->result();
    }
}

This query won't be shown in the profiler because it uses $this->db2. So how do make the profiler shows every query that is executed, doesn't matter from which database?

2 Answers 2

5

See this question. It's a much simpler solution. How can I display my database queries in the Codeigniter Profiler when I load my databases in my models?

Simply store your databases to the main CI class and the profiler will be able to access them.

function __construct()
{

    parent::__construct();

    $CI =& get_instance();
    if( is_null( $CI->Companies_db ) )
        $CI->Companies_db =& $this->load->database( 'companies', TRUE, TRUE );          

}
Sign up to request clarification or add additional context in comments.

1 Comment

If you're lucky, without further tweaking, this will work flawlessly. And it's 2.X compatible.
1

I had a similar problem. I was using a local mysql database and also accessing a remote Oracle database. The Oracle queries were not being shown in the profiler.

This article helped me to fix the problem:

http://www.gotphp.com/codeigniter-multiple-database-support/5468/

1 Comment

Here is an updated version of the post that fixes this for newer versions of Codeigniter: gotphp.com/codeigniter-profiler-extended/54358

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.