Reputation: 914
Im using Codeigniter 2.x and been trying to extend the database class and followed the wiki but im getting this error:
Fatal error: Uncaught Error: Call to undefined method MY_DB_mysqli_driver::where() in /system/libraries/Session.php on line 218
Error: Call to undefined method MY_DB_mysqli_driver::where() in /system/libraries/Session.php on line 218
On line 218 of /system/libraries/Session.php:
$this->CI->db->where('session_id', $session['session_id']);
My extended class is just the example from the wiki:
<?php
class MY_DB_mysqli_driver extends CI_DB_mysqli_driver
{
public function __construct($params)
{
parent::__construct($params);
log_message('debug', 'Extended DB driver class instantiated!');
}
public function get_first($table)
{
return $this->limit(1)->get($table);
}
}
Upvotes: 1
Views: 533
Reputation: 2162
The error you're getting is actually correct. I just downloaded version 2 to make sure of it.
You're extending the CI_DB_mysqli_driver
when what you're actually adding to it should be in the active records library and not the database driver.
Instead of extending your CI_DB_driver
create an extension of CI_DB_active_record
and add the get_first
functionality in it.
I must add that if that function is all you want to add to your core I wouldn't even bother to extend the core with it, since you're just trading one line by another line, there's no gain in it.
Also, most of these extensions can be done in a good base Model instead of hacking into the core.
Upvotes: 2