Welcome Guest, Not a member yet? Register   Sign In
Extending database class
#1

[eluser]agartzia[/eluser]
Hi! I'm trying to extend the database class (I'm using MySQL), but don't know where I'm going wrong...

Code:
//
// file: application/libraries/MY_CI_DB_mysql_driver.php
//
class MY_CI_DB_mysql_driver extends CI_DB_mysql_driver {

    function get_num_rows() {
    
        if ($table != '')
        {
            $this->from($table);
        }
        
        unset($this->limit);
        
        $sql = $this->_compile_select();

        $result = $this->query($sql);
        
        return $result->num_rows();
    
    }//end function

}//end class

And in the controller...
Code:
$config['total_rows'] = $this->db->get_num_rows();

But I get...
Quote:Fatal error: Call to undefined method CI_DB_mysql_driver::get_num_rows() in \system\application\controllers\of.php on line 48

How I'm supposed to extend the database library?

Thanks!
#2

[eluser]agartzia[/eluser]
Noone can fix this up?
#3

[eluser]Craig A Rodway[/eluser]
[quote author="User Guide"]Note: he Database classes can not be extended or replaced with your own classes, nor can the main Controller class. All other classes are able to be replaced/extended.[/quote]

User Guide - Creating Libraries
#4

[eluser]BizComputing[/eluser]
The docs state in the "Creating Your Own Libraries" section:

Note: The Database classes can not be extended or replaced with your own classes, nor can the main Controller class. All other classes are able to be replaced/extended.

This may be your problem. although, the statement that a controller class cannot be extended or replaced cannot be fully correct since I've been using my own controller extension and the only difference is that it extends Controller rather than CI_Controller.
#5

[eluser]agartzia[/eluser]
Ops! Thanks. I'll figure out something...
#6

[eluser]xwero[/eluser]
in the AR library of the the 1.6 version they added the methods count_all and count_all_results i think you try to do the same.




Theme © iAndrew 2016 - Forum software by © MyBB