views:

180

answers:

1

Hi, guys!

I'm newbie in ZF and have some stupid question:

What's the best solution to calculate rows in the table if I work with inherited object of Zend_Db_Table_Abstract class?

For my first web application I use QuickStart tutorial (link text) so if I want to calculate count of rows in the table in controller the simplest solution will be something like that:

$guestbooks = new Default_Model_GuestBook();
$count = count($guestbooks->fetchAll());

But I don't think that fetchAll() is the best solution just to calculate rows in the table because GuestBook table can be really huge. May be it is possible to use something much more easy and simple?

I found in manual that it is possible to work direct with DB Adapter (like $db->query("SELECT COUNT(*) FROM GuestBook");), but in QuickStart tutorial I haven't got that object in controller and I really don't want to create it only for one simple action.

Will be waiting for suggestions!

Thanks

A: 

Your model already contains DB Adapter because it also works with DB. You can get access to DB Adapter using getAdapter() method.

$questbooks->getAdapter()->query("SELECT COUNT(*) FROM GuestBook");
Kirzilla
Oh, thank you very much. Did not know about that