0

Currently right now I'am using Zend_DB_Select, I would like to return the rows as objects so that I can use methods like save(), delete()

Function includes:

    $table = self::instance();
    $select = $table->getAdapter()->select();
    $select->from('table1');
    if($where != '')
    {
        $select->where($where);
    }
    $select->limit($count);
    $select->order('id DESC');

    $rs = $select->query()->fetchAll();

So right now Iam passing an array instead of object types.

2 Answers 2

3

If you want to operate on your resulting rows as objects (to call save(), delete() on them and so on) you need to use Zend_Db_Table_* and not just Zend_Db_* for your requests.

That way your resultset will be Zend_Db_Table_Row objects (instead of arrays or stdClass objects) and those objects have methods such as save() and delete() that you can call to manipulate and update individual rows in your code.

Start reading here:

http://framework.zend.com/manual/en/zend.db.table.html

Sign up to request clarification or add additional context in comments.

Comments

3

Try this:

$rs = $select->query()->fetchAll(Zend_Db::FETCH_OBJ);

With Zend_Db::FETCH_OBJ, zend will return objects. It's all about fetch modes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.