Zend framework select where not working

I have the following that is to fetch only records that have the field “loan_cycle_number” = 0; yet it still fetches all the records. I have googled all I can and still no solution found:

        $groups = new Application_Model_GroupsMapper();
        $db = $groups->getDbTable()->select();
        $select->where('loan_cycle_number = ?', 0);

        $rows = $groups->fetchAll($select);

the getDbTable method is like so

    public function getDbTable()
        if (null === $this->_dbTable) {
        return $this->_dbTable;


well its

SELECT registration_date FROM groups WHERE loan_cycle_number =  0;

Have you checked the actual SQL query that your code generates/executes? According to [URL=“http://framework.zend.com/manual/en/zend.db.table.html”]the docs, you should be doing something similar to…*

$groups = new Application_Model_GroupsMapper;
$rows = $groups->getDbTable()->fetchAll(
    $groups->getDbTable()->select()->where('loan_cycle_number = ?', 0)

*I’ve never used ZF, so maybe wrong. :cool:

Thanks all. I swapped my code with Anthony’s and it works now. Apart from the error having this

       $db = $groups->getDbTable()->select();

instead of

       $select = $groups->getDbTable()->select();

in the code I posted earlier, I think both codes should work but my doesn’t and Anthony’s does. Any way thanks for your help am happy now :smiley:

I’m wondering if this isn’t a reserved words issue?

Group is in Mysql, maybe Groups is in the ZF mapper?

Sorry, for this long shot, but I don’t know enough about this package either.

What is the straight SQL statement that brings back the result you want?

(using whatever you manage your dbase with, PhpMyAdmin etc)