本文介绍了php PDO可以获取两个结果集吗?如果是,则最好是1个结果集或大于1个结果集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果可能,我如何获取两个结果集:
If is posible, how can I fetch two results sets:
$sth=$dbh->prepare("SELECT * FROM tb1 WHERE cond1;
SELECT * from tb2 Where cond2");
$sth->execute();
$row=$sth->fetchAll(); print_r ($row);
这是两个完全不同的表(没有共同点).
These are two completely different tables (no fiels in common).
推荐答案
是的,只要正在使用的数据库支持,PDO
即可获取两个(或更多)行集.我认为 MS SQL Server 和 MySQL 都支持此功能,但是在编写 SQLite 时不支持.
Yes PDO
can fetch two (or more) rowsets, as long as the database you are using supports it. I think MS SQL Server and MySQL both support this functionality, but at the time of writing SQLite does not.
您想要的功能是 PDOStatement :: nextRowset
因此,在上面的示例中,您可能会执行类似的操作;
So in your example above, you might do something like;
$sth = $dbh->prepare("SELECT * FROM tb1 WHERE cond1;
SELECT * FROM tb2 WHERE cond2");
$sth->execute();
$rowset1 = $sth->fetchAll();
$sth->nextRowset();
$rowset2 = $sth->fetchAll();
print_r($rowset1);
print_r($rowset2);
单个存储过程返回多个行集是完全合理的.
It's perfectly reasonable for a single stored procedure to return more than one rowset.
这篇关于php PDO可以获取两个结果集吗?如果是,则最好是1个结果集或大于1个结果集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!