开发者

zend db intersect

Does Zend_Db_Select object support Intersect?. It supports union (i.e this is possible, $db->select->union($sql1,$sql2) ), but when I look at the documentation, there is no method like intersect.

So How else is intersection开发者_如何转开发 possible with Zend_Db?


As much as I don't want to say this, but Zend_Db_Select does not support anything with INTERSECT. You will have to use your ingenuity to make this possible. You can extend Zend_Db_Select to add that functionality or build your SQL string and use the Adapter to fetch the records.

It shouldn't be too hard to accomplish the following by extending Zend_Db_Select

$sql1 = new My_Db_Select($db);
$sql1->from('tbl1');
$sql2 = $db->select();
$sql2->from('tbl2');
$sql1->intersect($sql2); // alternate usage, $sql1->intersect($sql2, $sql3, $sql4);
echo $sql1; // prints SELECT * FROM tbl1 INTERSECT SELECT * FROM tbl2

In order to accomplish that, you will have to create a storage for your intersect objects when adding objects via My_Db_Select::intersect and then create My_Db_Select::assemble to first call $sql = parent::assemble and then loop through the intersect parts and append each call to assemble on each. foreach($intersect as $select) $sql .= ' INTERSECT ' . $select->assemble();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜