0

How can I use the mysql instance inside of a library in codeigniter if I would like to execute queries. The class looks like

class Dtables {

    private $_db;

    function __construct()
    {
        //initialize $_db;

    }

    function mysql()
    {
        $sQuery ="//some mysql query string";
        $this->db->query($sQuery);
    }
}

1 Answer 1

3

You need to reference the CI object instance in your library:

class Dtables {

    private $CI;

    function __construct()
    {
        $this->CI =& get_instance();
        $this->CI->load->database(); 
    }

    function mysql()
    {
        $sQuery ="//some mysql query string";
        $this->CI->db->query($sQuery);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.