开发者

Zend Framework. The best solution to calculate rows in the table

开发者 https://www.devze.com 2022-12-17 06:00 出处:网络
I\'m newbie in ZF and have some stupid question: What\'s the best solution to calculate rows in the table if I w开发者_运维知识库ork with inheritedobject of Zend_Db_Table_Abstract class?

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

What's the best solution to calculate rows in the table if I w开发者_运维知识库ork 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


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");
0

精彩评论

暂无评论...
验证码 换一张
取 消