Search code examples
phpzend-frameworkzend-db

How can I get Zend Db to return a rowset rather an array when performing a UNION query?


I have a result set that is the result of a MySQL UNION query. The code I am using to fetch the data is:

$union_select = $PagesTable->getAdapter()->select()
        ->union(array('(' . $legal_resources_select . ')', '(' . $pages_select . ')'));
$PagesTable->getAdapter()->fetchAll($union_select)

$PagesTable extends Zend_Db_Table_Abstract. The full select is too big to post here and I don't think it is relevant to this particular question. If I am wrong let me know.

Currently this is returning an array of results, but I want it to return a rowset object. I must also be able to specify the $_rowClass. This is necessary so I can add methods for formatting and manipulating the returned values.

Is this possible?


Solution

  • You cannot. The result set you are fetching is a composite, and not a set of Rows from the DB, so even if it were possible, its a pretty bad idea.

    Zend_Db_Table is an implementation of the Table Data Gateway pattern more than Active Record.

    What you describe would be possible usually under Active Record, and to do so, I'd suggest looking at Doctrine 1.2 rather than Zend_Db_Table.