Php Zend Framework : Using Zend_Db_Select to return objects
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.
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
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.
精彩评论