Zend_Db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Zend_Db

Post by shiznatix »

As you may know, Im getting started with the Zend Framework because of silly bosses. In my framework I have made it simple to execute the most common queries so if I want do do this query:

Code: Select all

SELECT
    `headline`, `url_headline`, `posted_time`
FROM
    table_name
ORDER BY
    `id`
DESC
LIMIT 5

//then the whole execute and get data and whatnot...
I would just do this:

Code: Select all

$news = $this->NEWS->get_list(array('headline', 'url_headline', 'posted_time'), null, null, 'ORDER BY `id` DESC LIMIT 5');
which makes $news an array with each element being a stdClass of the model ($this->NEWS) and the variables of the fields being what was queried from the db. It works very well and its super easy.

Now! The Zend Framework way! I can't seam to find what would be the Zend equivilant of my get_list() function. The only thing I see is the fetchAll which I find to be silly because I don't want to fetch them all, just some. Also, I want to specify which rows I will be returning because in table with 30 some rows, all I need is 2.

The zend framework website seams to be down (no suprise) so I can't check there but I remember looking for it before and not being able to find any answers so now I ask you guys who might have some expierence with the framework.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

fetchAll() means "fetch all records in the result set", almost like

Code: Select all

foreach( $row=$result->fetchRow() ) {
  $allResults[] = $row;
}
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

why not just use your solution instead of Zend's? That is the only real redeeming quality I found in the Zend framework... you aren't really forced into using any certain component. In my opinion Zend_Db is overly complicated and counter-intuitive. When I was using the Zend framework I used adodb_lite. Much better.
Post Reply