在Php存储过程中获取查询 [英] Fetch Queries In Php Stored procedure

查看:75
本文介绍了在Php存储过程中获取查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了存储过程来从数据中获取查询,这是代码:



I have written stored procedure to fetch queries from data, Here is the code :

BEGIN
SELECT `posts`.`id`, `title`, `slug`, `image`,`labelid` FROM posts JOIN postlabels ON (posts.id=postlabels.postid and unpublish='0') WHERE labelid='13' ORDER BY `posts`.`id` DESC LIMIT 5;
SELECT `posts`.`id`, `title`, `slug`, `image`,`labelid` FROM posts JOIN postlabels ON (posts.id=postlabels.postid and unpublish='0') WHERE labelid='14' ORDER BY `posts`.`id` DESC LIMIT 5;
END





但执行后,我只能得到来自数据库的第一个查询,如何获取剩余的'n'个查询!



But after execution , i am getting only the first query from database , How to fetch remaining 'n' queries !

推荐答案

您还没有提供任何关于您希望以后数据的真实信息用过的。



如果我认为你正在寻找单个记录集:



如果你放置关键字UNION在每个select语句之间,您将获得包含所有请求记录的单个记录集。它们在整个UNION中都是独一无二的。如果您希望允许非唯一条目,请使用UNION ALL。



如果不寻找单个记录集:



如果您在不同的部分中为输出返回多个记录集,则最好分别运行每个查询,然后更新相应的区域 - 而不是返回多个记录集的单个查询。如果位置非常具体,这允许您考虑空记录集。



You haven't given any real information as to how you want the data to later be used.

If I presume you're looking for a single record set:

If you place keyword UNION between each select statement you'll get back a single record set containing all of your requested records. They will be unique throughout all of the UNION. If you wish to allow non-unique entries, use UNION ALL.

If not looking for a single recordset:

If you're returning multiple record-sets for output in different sections, you would probably be best off running each query separately and then updating the appropriate area - rather than a single query returning multiple record sets. This allows you to take into account empty record sets if locations are very specific.


这篇关于在Php存储过程中获取查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆