>
> Hi, is it possible to easily combine two db select objects. i.e. take the
> where out of one and add it to another one?
>
> I know you can get parts but then how do you inject that back to another
> select object? If not it would be quite a nice feature to allow parts to
> be interchanged.
>
This was not a specific design goal of Zend_Db_Select, but in some cases you
can do it. You probably have to
$select1 = $db->select()
->from('table1')
->where('foo = ?', 123);
$select2 = $db->select()
->from('table2');
foreach ($select1->getPart('where') as $w) {
$select2->where($w);
}
This example doesn't handle OR terms in the where clause. Basically, to
repurpose any clause that Zend_Db_Select can return, you'd have to duplicate
quite a lot of code from the Zend_Db_Select class.
In almost all cases, it'd be easier to manage information for your queries
in a way that is more tailored to your application, and then use this
information to create both $select1 and $select2 in turn.
Regards,
Bill Karwin
--
View this message in context: http://www.nabble.com/Combine-two-DB_Select-Objects-tp19373550p19377190.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论