Re: Cursors and PHP - Mailing list pgsql-general

From Tom Lane
Subject Re: Cursors and PHP
Date
Msg-id 10708.1082218679@sss.pgh.pa.us
Whole thread Raw
In response to Cursors and PHP  (Steve Manes <smanes@magpie.com>)
Responses Re: Cursors and PHP
List pgsql-general
Steve Manes <smanes@magpie.com> writes:
>      $query = "SELECT get_user_data('$cursor', $user_id);FETCH ALL IN
> $cursor;";

>      $res =& $dbh->query($query);

Hm.  This will return two different, not-compatible result sets (the
SELECT's output and then the FETCH's).  I don't know how PHP is defined
to react to that.  It seems that it's just discarding the first result
set and giving you the second, but is that specified behavior or is it
a bug that may get fixed someday?  Might be best to do this in two
queries.

> Question #2: I'm using a persistent database connection.  To avoid
> leaving an open cursor laying around I make another call to close the
> cursor after the result set is fetched.  Do I need to do this or will
> the cursor be closed implicitly by Apache/PHP after the page is delivered?

The backend will implicitly close the cursor at transaction end.  If the
connection-pooling code is set up to issue a COMMIT after the page is
processed, you need not close the cursor separately.

            regards, tom lane

pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: build contrib
Next
From: Ken Godee
Date:
Subject: Re: Python to postgresql interface