View Single Post
  #2 (permalink)  
Old 10-05-2007, 01:19 AM
Elemental's Avatar
Elemental Elemental is offline
Senior Member
 
Join Date: Jul 2007
Posts: 122
Default

I'm not sure I completely follow your questions, but here's I deal with it all...

For a database connection I will reuse often or need to access more than just a couple of tables in I create and register an adapter via Zend_Db::factory();

Code:
Zend_registry::set('dbDefault',
                   Zend_Db::factory('Pdo_Mysql', array(
                                    'host'     => '127.0.0.1',
                                    'username' => 'webuser',
                                    'password' => 'xxxxxxxx',
                                    'dbname'   => 'test'
                  )));

then I create a model by extending Zend_Db_Table
Code:
class Bugs extends Zend_Db_Table_Abstract
{
    protected $_name = 'bugs';
}
If that table is in my default adapters db its straight forward
Code:
$table = new Bugs();
If that table is in another adapter:
Code:

$db = Zend_Registry::get('myDbAdapter');
$table = new Bugs(array('db' => $db));
now you have a table object and you can run your queries via the docs...
since its a Zend_Db_Table type object the results will be of type Zend_Db_Table_Rowset.

The rowset can be turned into an array and you can mold it to your needs then feed the array to the view, etc.
Reply With Quote