Thread: Using Cursors in PHP

Using Cursors in PHP

From
Andreas Schmitz
Date:
Hello *,

I am just wondering if it is possible to use cursors within PHP. I need to
page query result from a big table and I am looking for a solution to avoid
scanning the complete table using limit and offset.

any ideas ?

best regards

-andreas




Re: Using Cursors in PHP

From
"scott.marlowe"
Date:
On Wed, 6 Aug 2003, Andreas Schmitz wrote:

>
> Hello *,
>
> I am just wondering if it is possible to use cursors within PHP. I need to
> page query result from a big table and I am looking for a solution to avoid
> scanning the complete table using limit and offset.

Yes, you can use cursors, no you can't expect them to survive from one
page to the next.

Luckily, Postgresql is smart enough to use indexes when you use offset
limit, but, of course, it must internally create the result set up to and
including the last row returned by the limit / offset.


Re: Using Cursors in PHP

From
Markus Bertheau
Date:
В Срд, 06.08.2003, в 17:51, scott.marlowe пишет:
> On Wed, 6 Aug 2003, Andreas Schmitz wrote:
>
> >
> > Hello *,
> >
> > I am just wondering if it is possible to use cursors within PHP. I need to
> > page query result from a big table and I am looking for a solution to avoid
> > scanning the complete table using limit and offset.
>
> Yes, you can use cursors, no you can't expect them to survive from one
> page to the next.

What about the new feature in cursors "WITH HOLD"? Don't they survive?

--
Markus Bertheau <twanger@bluetwanger.de>

Attachment

Re: Using Cursors in PHP

From
"scott.marlowe"
Date:
On 8 Aug 2003, Markus Bertheau wrote:

> В Срд, 06.08.2003, в 17:51, scott.marlowe пишет:
> > On Wed, 6 Aug 2003, Andreas Schmitz wrote:
> >
> > >
> > > Hello *,
> > >
> > > I am just wondering if it is possible to use cursors within PHP. I need to
> > > page query result from a big table and I am looking for a solution to avoid
> > > scanning the complete table using limit and offset.
> >
> > Yes, you can use cursors, no you can't expect them to survive from one
> > page to the next.
>
> What about the new feature in cursors "WITH HOLD"? Don't they survive?

I don't think so.  Basically, PHP is supposed to reset the connection if
it's persistant, and if it isn't persistant, then it's always a new
connection, which means a cursor shouldn't survive.

But I'm NOT familiar with "WITH HOLD" right now, so someone else who knows
that better may have a more definitive answer.


Re: Using Cursors in PHP

From
Rod Taylor
Date:
> I don't think so.  Basically, PHP is supposed to reset the connection if
> it's persistant, and if it isn't persistant, then it's always a new
> connection, which means a cursor shouldn't survive.
>
> But I'm NOT familiar with "WITH HOLD" right now, so someone else who knows
> that better may have a more definitive answer.

Yup.. This is where you setup a little Java to deal with persistent
database elements like this and hook into it via PHP.  It's a little
nasty at the moment (though functional) but is supposedly greatly
improved in PHP 5.

http://ca2.php.net/manual/en/ref.java.php

Attachment

Re: Using Cursors in PHP

From
"scott.marlowe"
Date:
On Fri, 8 Aug 2003, Rod Taylor wrote:

> > I don't think so.  Basically, PHP is supposed to reset the connection if
> > it's persistant, and if it isn't persistant, then it's always a new
> > connection, which means a cursor shouldn't survive.
> >
> > But I'm NOT familiar with "WITH HOLD" right now, so someone else who knows
> > that better may have a more definitive answer.
>
> Yup.. This is where you setup a little Java to deal with persistent
> database elements like this and hook into it via PHP.  It's a little
> nasty at the moment (though functional) but is supposedly greatly
> improved in PHP 5.
>
> http://ca2.php.net/manual/en/ref.java.php

Java providing connection pooling for PHP.  Sweet!


Re: Using Cursors in PHP

From
Bruce Momjian
Date:
scott.marlowe wrote:
> On 8 Aug 2003, Markus Bertheau wrote:
>
> > ?? ??????, 06.08.2003, ?? 17:51, scott.marlowe ??????????:
> > > On Wed, 6 Aug 2003, Andreas Schmitz wrote:
> > >
> > > >
> > > > Hello *,
> > > >
> > > > I am just wondering if it is possible to use cursors within PHP. I need to
> > > > page query result from a big table and I am looking for a solution to avoid
> > > > scanning the complete table using limit and offset.
> > >
> > > Yes, you can use cursors, no you can't expect them to survive from one
> > > page to the next.
> >
> > What about the new feature in cursors "WITH HOLD"? Don't they survive?
>
> I don't think so.  Basically, PHP is supposed to reset the connection if
> it's persistant, and if it isn't persistant, then it's always a new
> connection, which means a cursor shouldn't survive.

Actually, that brings up a problem --- our RESET ALL doesn't close
cursors that are kept open using WITH HOLD.

However, you are right that you can't be sure you will get the same
backend when you connect via a new page, so WITH HOLD doesn't help here.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073