Page 1 of 1

Zend_Db

Posted: Wed Dec 05, 2007 6:18 am
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.

Posted: Fri Dec 07, 2007 4:38 pm
by volka
fetchAll() means "fetch all records in the result set", almost like

Code: Select all

foreach( $row=$result->fetchRow() ) {
  $allResults[] = $row;
}

Posted: Fri Dec 07, 2007 5:52 pm
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.