Zend 框架选择对象和 UNION()
我很确定这在 Zend Framework 中是不可能的(我已经搜索了网络、文档和问题跟踪器),但我只是想确定一下,所以我在这里问。
$select = $this->select();
$select->union($select1, $select2);
这当然行不通。解释我需要什么。我需要使用 UNION() 合并 SELECT 查询中的 2 个表,我知道我可以这样做:
$select = "$select1 UNION $select2";
问题是它会返回一个字符串,我需要获取一个选择对象,以便我可以将它与 Zend_Paginator 一起使用。
我已经通过修改数据库架构解决了这个问题,但我只是好奇是否有一些解决方法。
I'm pretty sure this is not possible in Zend Framework (I have searched the Web, the documentation and issue tracker) but I just want to make sure so I'm asking here.
$select = $this->select();
$select->union($select1, $select2);
That doesn't work of course. To explain what I need. I need to use UNION() to merge 2 tables in a SELECT query, I know I could just do:
$select = "$select1 UNION $select2";
The problem is that would return a string and I need to get a select object so I can use it with Zend_Paginator.
I have already solved the issue by modifying my database architecture but I'm just curious if there is some workaround for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
以下是我为创建联合所做的操作:
请记住,
Db_Select
的__toString
将打印出该选择生成的 SQL,以帮助您进行调试。Here's what I've done to make a union:
Remember
Db_Select
's__toString
will print out the SQL generated by that select, to help you debug.Zend_Db_Select 有一个 union 方法 所以我想如果您可以使用选择对象构建查询,这是可能的。我没有将 Zend_Db_Select (或表子类)与 union 一起使用,但我想你可以做类似的事情
Zend_Db_Select has a union method so I'd have thought it is possible, if you can build your query using a select object. I haven't used Zend_Db_Select (or the table subclass) with union but I'd imagine you can do something like
完整的示例:
生成的查询:
SELECT
reservations
.* FROMreservations
WHERE (id='5658') UNION SELECTres_finished
.* FROMres_finished
WHERE (id='5658') UNION SELECTres_cancel
.* FROMres_cancel
WHERE (id='5658') UNION SELECTres_trash
.* 来自res_trash
地点 (id='5658')a complete example:
and the generated query:
SELECT
reservations
.* FROMreservations
WHERE (id='5658') UNION SELECTres_finished
.* FROMres_finished
WHERE (id='5658') UNION SELECTres_cancel
.* FROMres_cancel
WHERE (id='5658') UNION SELECTres_trash
.* FROMres_trash
WHERE (id='5658')这个实际示例显示了一个函数,该函数返回特定年份(艺术品博客)的最新或可用的收藏博客条目的行集:
This practical example shows a function that returns a rowset of either latest or if a available favourite blog entries of a specific year (artwork blog):
这就是它对我来说的工作方式:
在两个查询中获取必要的数据后,UNION 语法如下所示:
This is how it works for me:
After getting the necessary data in both queries the UNION syntax goes like this: