Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Call to a member function query() on a non-object
#11

[eluser]Creox[/eluser]
[quote author="John_Betong_002" date="1308254970"]Have you tried using another table name?

Also try http://localhost/phpmyadmin/index.php and check your database and tables.
 
 [/quote]

John,

The tbales are in the database that i connect to succesffully.

When I exectue the following code

Code:
$query = $this->db->query('SELECT * FROM users WHERE UserID = '.$userID.' LIMIT 1');
        return $query->result();

I expect to get a result back.

However I get the following

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: User_model::$db

Filename: models/user_model.php

Line Number: 14

Fatal error: Call to a member function query() on a non-object in C:\wamp\www\GREENStore\application\models\user_model.php on line 14

i have autoloaded the database in config/autoload.php

Code:
$autoload['libraries'] = array('database');

What else could it be? This is driving me insane.

I have just downloaded CI v2.01 at the error still occurs.

Please help.

Thanks

Ciaran
#12

[eluser]John_Betong_002[/eluser]
It looks as though your database class is not getting loaded.

Try setting your ./application/config/config.php and make sure everything is getting loaded.
Code:
$config['log_threshold'] = '4';
 

Also try this:
Code:
error_reporting(-1);
  ini_set('display_errors', 1);

  $this->load->database();

  $query = $this->db->query('SELECT * FROM users WHERE UserID = '.$userID.' LIMIT 1');
  return $query->result();
 
 
#13

[eluser]Creox[/eluser]
Sorry John, That didnt work.

The ouput is now

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: User_model::$load

Filename: models/user_model.php

Line Number: 18

Fatal error: Call to a member function database() on a non-object in C:\wamp\www\GREENStore\application\models\user_model.php on line 18
#14

[eluser]John_Betong_002[/eluser]
Did you check your error log?

If there are no errors to be fixed in your error log then I would try copying the example from "Creating your own Models" and change the values where required.

http://ellislab.com/codeigniter/user-gui...odels.html
Code:
<?php

class Blogmodel extends CI_Model {

    var $title   = '';
    var $content = '';
    var $date    = '';

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function get_last_ten_entries()
    {
      error_reporting(-1);
      ini_set('display_errors', 1);

      $this->load->database();

      $query = $this->db->get(' users', 10);
      
      return $query->result();
    }//

}//
 
 
#15

[eluser]InsiteFX[/eluser]
Show your code were your loading your model!

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB