codeigniter Call to a member function query() on a non-object

if you are getting this error, then the first step towards the solution is to check that the ‘database’ library is autoloaded in the “autoload.php” file in the config directory under system/application

if not please add that. i.e. $autoload[‘libraries’] = array(‘database’, ‘session’);