从 PHP 中的存储过程检索多个结果集 (ibm_db2)
当对存储过程的单个调用返回多个结果集时,您可以使用 ibm_db2 API 的 db2_next_result 函数来检索结果集。
准备工作
您必须具有由具有多个结果集的 db2_exec 或 db2_execute 函数返回的语句资源。
过程
要检索多个结果集,请执行以下操作:
示例
从存储过程检索多个结果集。
$stmt = db2_exec($conn, 'CALL multiResults()');
print "Fetching first result set\n";
while ($row = db2_fetch_array($stmt)) {
// work with row
}
print "\nFetching second result set\n";
$result_2 = db2_next_result($stmt);
if ($result_2) {
while ($row = db2_fetch_array($result_2)) {
// work with row
}
}
print "\nFetching third result set\n";
$result_3 = db2_next_result($stmt);
if ($result_3) {
while ($row = db2_fetch_array($result_3)) {
// work with row
}
}
下一步要执行的操作
准备好关闭与数据库的连接时,请调用 db2_close 函数。 如果尝试关闭使用 db2_pconnect创建的持久连接,那么关闭请求将返回 TRUE ,并且持久 IBM® 数据服务器客户机连接仍可供下一个调用者使用。