Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 37E166325DE for ; Tue, 15 Jun 2010 06:44:06 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 45043-01 for ; Tue, 15 Jun 2010 09:43:58 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wy0-f174.google.com (mail-wy0-f174.google.com [74.125.82.174]) by mail.postgresql.org (Postfix) with ESMTP id 4148B632521 for ; Tue, 15 Jun 2010 06:43:58 -0300 (ADT) Received: by wyb40 with SMTP id 40so4609032wyb.19 for ; Tue, 15 Jun 2010 02:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type; bh=zOv0iGDrbvpJ9+bxdpXIVw9yBM7ebgGq/gaon5LqGDg=; b=dPbMW6Rb26Tn7hBcA24kUD2qW+ZTSqhNMsCWB754So1BewuXUFm8CKw2q78BwN8+jM /rhltiRxsykFOxGfmKM+0qHlqnt6BvtdNIx2ffHqY1jgBQc8FcIAnGK+qC7dXMqd7cJK I8da74qmYzkjWxnANoGq4CPv17pXnyV43OzGI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=XxiSs+5VnYrD0TBcg4CxnvXlX5s94tuXWNMzV2JH8+3XzVC0DUnkwLfS8VFtMmcVW5 n9+sKEmDbHh5zgl3C2L33StE0OJwepbBfWVGD/wjnUK+dwC1GIG6LVPo2f02oCfl0M+i pGhkseJf52o8baxX2Z2c9T7owSRWwzUQNGsp8= Received: by 10.227.133.138 with SMTP id f10mr6960789wbt.37.1276595035771; Tue, 15 Jun 2010 02:43:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.188.209 with HTTP; Tue, 15 Jun 2010 02:43:35 -0700 (PDT) In-Reply-To: <8f468dc246fb6075f2a1f46b09f71a6d@xs4all.nl> References: <8f468dc246fb6075f2a1f46b09f71a6d@xs4all.nl> From: Thom Brown Date: Tue, 15 Jun 2010 10:43:35 +0100 Message-ID: Subject: Re: large resultset To: vinny Cc: AI Rumman , pgsql-php@postgresql.org Content-Type: multipart/alternative; boundary=0016e659f8d8a1149e04890e71d6 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-10 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201006/4 X-Sequence-Number: 4143 --0016e659f8d8a1149e04890e71d6 Content-Type: text/plain; charset=ISO-8859-1 On 15 June 2010 10:40, vinny wrote: > > On Tue, 15 Jun 2010 10:33:05 +0100, Thom Brown > wrote: > > On 15 June 2010 09:31, AI Rumman wrote: > > How to return large resutlset (almost 2 millions record) in php? > > > > Presumably this is so people can download results rather than display > > them in a browser? > > > > Here's a basic a raw version of what you can do: > > > > $db = pg_connect($connection_string); > > > > $results = pg_query($db, $query); > > > > while ($result = pg_fetch_array($results) > > { > > echo implode("|", $result) . "\n"; //typo before > > } > > > > pg_close($db); > > > > Obviously that wouldn't do by itself, but it's quite simple to loop over > > a result set. > > > > Regards > > > > Thom > > > > If that's the case surely you'd use some SQL to merge the data into one > long string and return it in a single record. > Looping over two million results is going to take a while, not to mention > quite a bit of memory. > v. > > I don't understand. Return all data as a single massive string? Thom --0016e659f8d8a1149e04890e71d6 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 15 June 2010 10:40, vinny &= lt;vinny@xs4all.nl> wrote:=

On Tue, 15 Jun 2010 10:33:05 +0100, Thom Brown <thombrown@gmail.com>
wrote:
> On 15 June 2010 09:31, AI Rumman =A0= wrote:
> =A0How to return large resutlset (almost 2 millions record) in php? >
> Presumably this is so people can download results rather than display<= br> > them in a browser?
>
> Here's a basic a raw version of what you can do:
>
> $db =3D pg_connect($connection_string);
>
> $results =3D pg_query($db, $query);
>
> while ($result =3D pg_fetch_array($results)
> {
> =A0=A0=A0 echo implode("|", $result) . "\n"; //typ= o before
> }
>
> pg_close($db);
>
> Obviously that wouldn't do by itself, but it's quite simple to= loop over
> a result set.
>
> Regards
>
> Thom
>

If that's the case surely you'd use some SQL to merge t= he data into one
long string and return it in a single record.
Looping over two million results is going to take a while, not to mention quite a bit of memory.
v.


I don't understand.=A0 Return all data as= a single massive string?

Thom
--0016e659f8d8a1149e04890e71d6--