# PDO proposal: add PDOStatement::nextResult() method to support stored procedures

- Thread: https://externals.io/message/15929
- Original archive: https://news-web.php.net/php.internals/15929
- Started by Dan Scott on 2005-04-09T14:33:32+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #15929 — Dan Scott — 2005-04-09T14:33:32+00:00

URL: https://externals.io/message/15929#15929

Wez et al:

I've been writing a chapter on database programming with PHP, using
PDO, and ran across a scenario that has not yet been fulfilled by the
PDO API. Many databases (Apache Derby, DB2, Microsoft SQL Server,
MySQL 5, and PostgreSQL to a certain extent) support stored procedures
that can return multiple result sets. Database APIs typically set the
result set pointer to the first row of the first result set returned,
allow the application to iterate through the rows, and provide some
method to request the second result set from the database server.

In ODBC, for example, you would call SQLFetch() to iterate through the
rows of the first result set, then call SQLNextResult() to request the
next result set.

In the PHP realm, Unified ODBC defines odbc_next_result(); mssql
defines mssql_next_result(); PEAR::DB defines DB_Result:nextResult().

PDO, however, currently provides no means of working with the second
or subsequent result sets returned from a call to a stored procedure.

To build on the established naming practice from existing database
extensions, I propose that the PDO interface define the standard
method:
/* {{{ proto bool PDOStatement::nextResult(void)
Requests the next result set from the database
*/

Thanks,
Dan

Note: somewhat confusingly, mysqli defines `mysqli_next_result()`, but
this is used to retrieve the results of a multi-query... a very
different thing, and not something I advocate adding to PDO. They
might have trouble disambiguating that from the stored procedure case
when MySQL 5 reaches production status.

---

## #15930 — Jared Williams — 2005-04-09T14:46:37+00:00

URL: https://externals.io/message/15929#15930 · In reply to: #15929

> 
> I've been writing a chapter on database programming with PHP, 
> using PDO, and ran across a scenario that has not yet been 
> fulfilled by the PDO API. Many databases (Apache Derby, DB2, 
> Microsoft SQL Server, MySQL 5, and PostgreSQL to a certain 
> extent) support stored procedures that can return multiple 
> result sets. Database APIs typically set the result set 
> pointer to the first row of the first result set returned, 
> allow the application to iterate through the rows, and 
> provide some method to request the second result set from the 
> database server.
> 
> In ODBC, for example, you would call SQLFetch() to iterate 
> through the rows of the first result set, then call 
> SQLNextResult() to request the next result set.
> 
> In the PHP realm, Unified ODBC defines odbc_next_result(); 
> mssql defines mssql_next_result(); PEAR::DB defines 
> DB_Result:nextResult().
> 
> PDO, however, currently provides no means of working with the 
> second or subsequent result sets returned from a call to a 
> stored procedure.
> 
> To build on the established naming practice from existing 
> database extensions, I propose that the PDO interface define 
> the standard
> method:
> /* {{{ proto bool PDOStatement::nextResult(void) Requests the 
> next result set from the database */
> 
> Thanks,
> Dan
> 
> Note: somewhat confusingly, mysqli defines 
> `mysqli_next_result()`, but this is used to retrieve the 
> results of a multi-query... a very different thing, and not 
> something I advocate adding to PDO. They might have trouble 
> disambiguating that from the stored procedure case when MySQL 
> 5 reaches production status.
> 

Doesn't PDOStatement::nextRowset() do this?

Jared

---

## #15931 — Christopher Kings-Lynne — 2005-04-09T15:48:03+00:00

URL: https://externals.io/message/15929#15931 · In reply to: #15929

> PDO API. Many databases (Apache Derby, DB2, Microsoft SQL Server,
> MySQL 5, and PostgreSQL to a certain extent) support stored procedures

PostgreSQL to a certain extent, what the...?

Anyway, why do stored procs need to be treated differently to normal 
results?  In PostgreSQL they just return results like normal SELECTs...

Chris

---

## #15932 — Derick Rethans — 2005-04-09T15:57:08+00:00

URL: https://externals.io/message/15929#15932 · In reply to: #15931

> > […]
> 
> PostgreSQL to a certain extent, what the...?
> 
> Anyway, why do stored procs need to be treated differently to normal results?
> In PostgreSQL they just return results like normal SELECTs...

Because SPs can return multiple result sets...or can't PostGreSQL don't 
do this?

Derick

-- 
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org

---

## #15933 — Dan Scott — 2005-04-09T16:07:34+00:00

URL: https://externals.io/message/15929#15933 · In reply to: #15931

On Apr 9, 2005 11:48 AM, Christopher Kings-Lynne
<chriskl@familyhealth.com.au> wrote:
> > […]
> 
> PostgreSQL to a certain extent, what the...?
> 
> Anyway, why do stored procs need to be treated differently to normal
> results?  In PostgreSQL they just return results like normal SELECTs...
> 
> Chris
> 

Sorry Chris, no slight against PostgreSQL intended. I guess when I
think of "normal" SELECT statements, they return a single result set.
But then I'm coming at this from a different set of databases that use
CREATE PROCEDURE / CALL to deal with stored procedures, instead of
CREATE FUNCTION / SELECT in PostgreSQL's case. I do enjoy the learning
curve associated with database abstractions :)

I was reading through the PostgreSQL 8.0 docs and saw how functions
returned multiple result sets, but didn't see the corresponding
client-side API for calling it. Looking deeper at the docs, in pgsql
would it be pg_get_result()?

BTW, I have now added PDOStatement::nextRowset() documentation to the
manual. That's what I get for reading my own (incomplete)
documentation.

Dan

---

## #15934 — Christopher Kings-Lynne — 2005-04-10T03:19:07+00:00

URL: https://externals.io/message/15929#15934 · In reply to: #15933

> BTW, I have now added PDOStatement::nextRowset() documentation to the
> manual. That's what I get for reading my own (incomplete)
> documentation.

Oh multiple result sets per stored procedure...  I'm not sure that is 
possible in PostgreSQL...
