I recently upgraded to CodeIgniter 2.1. The below model code (machforms_model.php) was properly working in my previous CI install. I have also confirmed that my database.php file is identical to the previous install, so db configuration should not be the source of my problem. The error message I see now is: Fatal error: Call to a member function query() on a non-object in models/machforms_model.php on line 24, where line 24 is my first query attempt.
machforms_model:php
class machforms_model extends CI_Model
{
public function __construct() {
parent::__construct();
$CI =& get_instance();
$CI->machformsdb = $this->load->database('machforms', TRUE);
$this->machformsdb = $CI->machformsdb;
}
function deauthorize_user($user_guid) {
$sql = 'delete from ap_sessions where user_guid=?';
$sql_result = $machformsdb->query($sql,array($user_guid)); // LINE 24
}
}
I am uncertain why I receive the overload error. If other external file/config information may be the culprit, please advise and I will post accordingly.
$machformsdbis not defined in your functiondeauthorize_user. You should call$this->machformsdb.In addition: in your constructor,
$thisis already an instance ofCI_Modelso you don’t need to get the CodeIgniter singleton instance. You could just write: