Can php PDO fetch two results sets? And If yes, what is better 1 result set or more than 1?(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 个结果集哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php PDO 可以获取两个结果集吗?如果是,那么 1 个结果集或多于 1 个结果集哪个更好?


- PHP Count 布尔数组中真值的数量 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Laravel 仓库 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01