no name
no name

Reputation: 7

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

For the past 2 hours I am trying to find the solution to my error. I am trying to retrive the entries from a specific table, but it always saying

Fatal error: Call to a member function find() on a non-object in
web_performance/models/MongoDbConnection.php on line 18

Any suggestions what to do ?

This is my db connection class

class MongoDbConnection {
    private $_mongoDb=null;
    private $_table;


    public function __constructor($dbAddress='localhost') {
        $this->_mongoDb=new Mongo($dbAddress);
    }

    public function setTable($argTableName){
        $this->_table=$this->_mongoDb->$argTableName;
        return $this;
    } 

    //select method
    public function find(){
        $this->_table->find(); // <- Line 18
        return $this;
    }

    //create insert method
    /*public function insert($values){
        $this->_table->insert($values);
        return $this;
    }*/

    //update method
    public function update($values){
        $this->_table->update($values);
        return $this;
    }

    //delete method
    public function dbMongoDelete($values){
        throw new Exception('Delete not yet defined in '.__CLASS__);            
    }

//end class 
}

This is my Settings Class

module_load_include('php', 'web_performance', 'models/MongoDbConnection');

class BenchmarkingSettings {
    private $_mongoDb;
    static private $_instance;

    public function __construct() {
        $this->_mongoDb=new MongoDbConnection();    
    }

    static public function getInstance() {
        if (is_null(self::$_instance)) {
            self::$_instance=new BenchmarkingSettings();
        }
        return self::$_instance;
    }

    public function populateFormWithValueSettings(){
        $response=$this->_mongoDb->setTable("benchmarkingSettings")->find();

        return $response;
    }

}

Upvotes: 0

Views: 2380

Answers (1)

Clive
Clive

Reputation: 36955

Change this

public function __constructor($dbAddress='localhost') {

to

public function __construct($dbAddress='localhost') {

Upvotes: 1

Related Questions