From: Andrew McMillan <andrew@catalyst.net.nz>
To: sector119@mail.ru
Cc: pgsql-php@postgresql.org
Subject: Re: pg_pconnect+PostgreSQL cursors
Date: 27 Dec 2002 22:13:53 +1300
Message-ID: <1040980433.18767.16.camel@kant.mcmillan.net.nz> (raw)
In-Reply-To: <20021227061010.GA20033@city.gov.te.ua>
References: <20021227061010.GA20033@city.gov.te.ua>
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/
---------------------------------------------------------------------
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: andrew@catalyst.net.nz, sector119@mail.ru
Subject: Re: pg_pconnect+PostgreSQL cursors
In-Reply-To: <1040980433.18767.16.camel@kant.mcmillan.net.nz>
References: <20021227061010.GA20033@city.gov.te.ua> <1040980433.18767.16.camel@kant.mcmillan.net.nz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox