Re: multiple result sets from DB_common::execute()
| From: | Justin Patrin | Date: | Mon, 26 Jul 2004 23:05:59 +0000 |
| Subject: | Re: multiple result sets from DB_common::execute() | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13858@lists.php.net to get a copy of this message | ||
Oh, I see....
Looks like you call nextResult() on the result, so something like this:
$sth = $db->execute($stmt);
do {
while($rec = $sth->fetchRow()) {
//do something with $rec
}
} while($sth->nextResult());
----- Original Message -----
From: Al Partis <alpartis@thundernet.com>
Date: Mon, 26 Jul 2004 17:08:35 -0400
Subject: Re: [PEAR] multiple result sets from DB_common::execute()
To: pear-general@lists.php.net
Cc: papercrane@reversefold.com
At 04:34 PM 07/26/04, Justin Patrin wrote:
On Sun, 25 Jul 2004 12:41:59 -0400, Al Partis <alpartis@thundernet.com> wrote:
> Is it possible to receive multiple result sets from a call to
DB_common::execute()?
>
> I am calling a DB2 stored proc over ODBC that returns multiple
result sets. Is this possible through PHP/PEAR:DB? Based on my
reading of the documentation, this method returns a DB_result object
and nothing indicates to me that this object is a container class that
could contain multiple result sets. Am I reading this wrong?
>
A DB_Result has fetching methods. Please look at the documentation or
a tutorial about how to loop through the result set:
$db = DB::connect($dsn);
$result = $db->query('SELECT ...');
while($record = $result->fetchRow()) {
//do something with $record
}
Thanks Justin, but the problem I'm having is not in retrieving
multiple rows from a single result set, but in accessing multiple
result sets. I'm calling a stored procedure that returns multiple
result sets from the single call. This behavior is supported in at
least Sybase, MS SQL Server, and DB2 that I know of.
My code would look something like this:
$db = DB::connect($dsn);
$args = array($client_nbr);
$query = "call StoredProc001 (!)";
$pstmt = $db->prepare($query);
$result = $db->execute($pstmt, $args);
If StoredProc returns 3 result sets, how do I access each of them
individually so I can retrieve their contents?
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--