Skip site navigation (1) Skip section navigation (2)

Re: pg_fetch_array

From: ljb <ljb220(at)mindspring(dot)com>
To: pgsql-php(at)postgresql(dot)org
Subject: Re: pg_fetch_array
Date: 2004-06-15 00:04:57
Message-ID: calef8$2qr$ (view raw, whole thread or download thread mbox)
Lists: pgsql-php
Thanks(at)verymuch(dot)com wrote:
> Hello....
> I would like to know the performance of pg_fetch_array.  Cosider the code:
> $query = "select * from foo";
> $result = pg_query( $db, $query );
> while ($row = pg_fetch_array($result))
> {
>    $a = $row["a"];
>    $b = $row["b"];
>    $c = $row["c"];
>    $d = $row["d"];
> }
> Does php need to read database everytime when pg_fetch_array is executed in
> the while loop or all the rows have been in the memory after pg_query?

The whole result query is stored in memory when pg_query returns, and
pg_fetch_array just gets the next row.

> If read database is needed, is there any method to copy all the things into
> memory by using other command? (because I have a application which needs
> large amount database update/retrieval and I wish the performance of the
> overall applications run faster.)
> or other method you would like to recommend in order to make the faster
> response time?

Actually, bringing the whole result into memory before processing any rows
can be slower, since the web server has to wait for the database server to
finish before it can start working on the data. So you can't get any
overlap of database and web server processing.  As far as I know, there
isn't any alternative currently in the PHP PostgreSQL interface; there are
asynchronous queries but you still can't process any rows until they all
come back.

In response to


pgsql-php by date

Next:From: Scott MarloweDate: 2004-06-15 04:51:26
Subject: Re: pg_fetch_array
Previous:From: ThanksDate: 2004-06-14 05:02:06
Subject: pg_fetch_array

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group