user505988
user505988

Reputation: 503

Zend Framework member 'function fetchAll() on a non-object '

I have set up a basic installation of ZF and I'm trying to connect to the database. I appreciate there are better ways of initializing the db using config.ini etc, but for the sake of tracking the bug down I have put the connection details straight in as an array.

$config=array('host'=>'localhost',
                   'username'=>'test_user',
                   'password'=>'test_pass',
                   'dbname'=>'test_db');

    $this->db= new Zend_Db_Adapter_Pdo_Mysql($config);
    $stmt="SELECT * FROM pages";

    $results=$this->db->fetchAll($stmt);

The code is called in the constructor of class Application_Model_Page{}

When I instance the model I get the following message: member 'function fetchAll() on a non-object '

I know this is because its not an object, but I don't understand why its failing.

I have done a standards mysql_connect and select using classic php and the above details and these work correctly.

I can also create an instance of Application_Model_Page if the db connection is not in the consructor. I just echo out 'hello world'

Can anyone point me out a reason why this maybe failing please?

John

Upvotes: 1

Views: 1045

Answers (1)

Alex Pliutau
Alex Pliutau

Reputation: 21947

Try to use $db instead of $this->db. I think that setter isn't available in Application_Model_Page class.

Upvotes: 2

Related Questions