Search code examples
phpmysqlzend-frameworkzend-db

Wrapper to Zend_Db is failing


All,

I wrote the following wrapper that extends Zend_Db class to provide db connectivity to my entire application. The db connectivity works fine, but it fails to execute queries when invoked from a different class.

class Testapp_DB extends Zend_Db {

        //Declare member variables.
        public $db          = null;
        public $db_host     = "";
        public $db_database = "";
        public $db_username = "";
        public $db_password = "";


 public function __construct()
        {

            //Read Database Info from Config File
            $this->db_host      = Testapp_Registry::get('config')->db->mysql->host;
            $this->db_database  = Testapp_Registry::get('config')->db->mysql->dbname;
            $this->db_username  = Testapp_Registry::get('config')->db->mysql->username;
            $this->db_password  = Testapp_Registry::get('config')->db->mysql->password;

            $db = Zend_Db::factory('Mysqli', array(
                'host'     => $this->db_host,
                'username' => $this->db_username,
                'password' => $this->db_password,
                'dbname'   => $this->db_database
            ));

            $db->getConnection(); //Works fine
            $this->db = $db;
 }
}

Trying to execute query in a PHP file that includes Testapp_DB - fails..

<?php

 $db = new Testapp_DB();
 print_r($db);  //I can see the DB object here
 $sql = 'SELECT * FROM tb_Log';
 $result = $db->fetchAll($sql, 2); //This method fails.. Don't know why. Any ideas?
 print_r($result);
?>

Can someone please explain, why the fetchAll method fails?

Thanks


Solution

  • *Zend_Db* doesnt have any method other than factory().

    I dont really get, what you are trying to solve this way, but as far as I can see you need to call query() this way

    $db->db->query();