Re: pg_pconnect+PostgreSQL cursors - Mailing list pgsql-php

From Andrew McMillan
Subject Re: pg_pconnect+PostgreSQL cursors
Date
Msg-id 1040980433.18767.16.camel@kant.mcmillan.net.nz
Whole thread Raw
In response to pg_pconnect+PostgreSQL cursors  (sector119@mail.ru)
List pgsql-php
On Fri, 2002-12-27 at 19:10, sector119@mail.ru wrote:
> Hi all
>
> <?
> $connection = pg_pconnect("dbname=$db user=$user password=$password");
> if (!isset($page))
> {
>     pg_exec($connection, "BEGIN WORK");
>     pg_exec($connection, "DECLARE all_data CURSOR FOR SELECT id,body FROM test")
> }
>
> $result = pg_exec($connection, "FETCH 1 FROM all_data");
> $info = pg_fetch_array($result, 0);
> print "|$info[0]|$info[1]|<br>\n";
> ?>
>
> When I execute this script at first without page parameter I'v got
> data to info array! when I execute it at other times I'v got nothing
> :(
>
> I've got closing of cursor and transaction! why??? I use permanent
> connection, why I've got closing of cursor and transaction!???

I'm not sure, from your description, but it may be something to do with
the fact that Apache allocates a server process to serve requests in a
round-robin fashion.

If you use Persistent connections, you will (most likely) get a
different database connection for each request (the apache process
connects persistently to the database, but your client session doesn't
connect persistently to any given apache process).

So it could be that you are seeing a previously opened cursor - default
Apache setups for development usually only have five processes serving
requests, so they go round fairly quickly.

If this is the case, I would imagine you would be seeing all sorts of
other wierd side-effects as well.

In general, cursors aren't the right answer to the problem when doing
web development.  Personally I have _never_ found a web problem which
they are suited to with PostgreSQL (although I have with Oracle).

PostgreSQL's " OFFSET <x> LIMIT <y> " functionality has been quite
useful, however.

Regards,
                    Andrew.
--
---------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St,  Wellington
WEB: http://catalyst.net.nz/         PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201     MOB: +64(21)635-694    OFFICE: +64(4)499-2267
           Survey for nothing with http://survey.net.nz/
---------------------------------------------------------------------


pgsql-php by date:

Previous
From: sector119@mail.ru
Date:
Subject: pg_pconnect
Next
From: GOLDBERG
Date:
Subject: Re: pg_pconnect