Monday 9 September 2019

Fatal error: Call to a member function insert() when using active records in CodeIgniter










When i try to access the database using CodeIgniters Active records it always gives me the error





Fatal error: Call to a member function insert() on a non-object



Fatal error: Call to a member function get() on a non-object




below is the settings in my database



$active_group = 'default';
$active_record = TRUE;


$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'test';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;

$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;


and i have auto-loaded it




$autoload['libraries'] = array('database','session');


and below is my model



class Leads_model extends CI_Model {

function __construct()
{
parent::__construct();

}

function insertq(){

$q=$this->db->insert('test',$data);

if ($q){

return true;
}

else
{
return false;
}


}
}



can someone please suggest me what am i doing wrong and why am i getting that error?


Answer



The problem was i had added some variables to get the autocomplete work in to the model core. That was causing the problem and its working after removing those.



but the auto complete doesn't seem to work now.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...