Re: using CURSOR with PHP

From: Andrew McMillan <andrew(at)catalyst(dot)net(dot)nz>
To: Eckhard Hoeffner <e-hoeffner(at)fifoost(dot)org>
Cc: PHP PostgreSQL <pgsql-php(at)postgresql(dot)org>
Subject: Re: using CURSOR with PHP
Date: 2002-05-18 12:09:51
Message-ID: 1021723791.30041.241.camel@kant.mcmillan.net.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

On Sat, 2002-05-18 at 23:03, Eckhard Hoeffner wrote:
> >
> >I don't use cursors in web applications myself, since PostgreSQL
> >supports the excellent "SELECT ... LIMIT <n> OFFSET <m>" syntax in all
> >of the cases where I might otherwise have done so.
>
> That's what I wanted to avoid as this results in a little more
> work.
>
> >That's my experience to date, anyway - I'm prepared to find somewhere a
> >cursor might be a requirement - I know that if you wanted to write
> >cross-database portable code you would probably need to work with them.
> >
> >Regardless, unless you open your database connection as a persistent
> >connection, the database connection will be closed when the script
> >finishes, and that should clean up all that is necessary.
>
> I used persistent connections, however, I got lots of <defunct>
> processes.
> If the CURSOR is closed when the script has finished (pg_connect),
> it makes no sense (for me) using it, because I can not move within
> the results.

Right, so your problem is you're trying to use CURSOR, which you are
leaving open on the off-chance your visitor will returns and wants to
see the 'next record' or something.

I think that really you just should bite the bullet and use the better
syntax on SELECT. You may have a little more programming work to do,
but it has little impact on performance as far as I can see.

PostgreSQL will optimise queries differently when they have LIMIT
clauses too.

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
Are you enrolled at http://schoolreunions.co.nz/ yet?

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Gaëtan de Menten 2002-05-18 15:14:46 Simple PHP/pgsql optimization question...
Previous Message Eckhard Hoeffner 2002-05-18 11:03:25 Re: using CURSOR with PHP