Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 32FD6632C49 for ; Tue, 15 Jun 2010 06:40:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 89083-09 for ; Tue, 15 Jun 2010 09:40:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp-vbr1.xs4all.nl (smtp-vbr1.xs4all.nl [194.109.24.21]) by mail.postgresql.org (Postfix) with ESMTP id 5F243632ABB for ; Tue, 15 Jun 2010 06:40:14 -0300 (ADT) Received: from roundcube.xs4all.nl (roundcube9.xs4all.nl [194.109.20.207]) by smtp-vbr1.xs4all.nl (8.13.8/8.13.8) with ESMTP id o5F9eBIm085982; Tue, 15 Jun 2010 11:40:11 +0200 (CEST) (envelope-from vinny@xs4all.nl) Received: from 82-170-94-236.vodafonevast.nl ([82.170.94.236]) by roundcube.xs4all.nl with HTTP (HTTP/1.1 POST); Tue, 15 Jun 2010 11:40:11 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: Tue, 15 Jun 2010 11:40:11 +0200 From: vinny To: Thom Brown Cc: AI Rumman , Subject: Re: large resultset In-Reply-To: References: Message-ID: <8f468dc246fb6075f2a1f46b09f71a6d@xs4all.nl> X-Sender: vinny@xs4all.nl (AARSeoKtvMrkggghCTTVOg==) User-Agent: XS4ALL Webmail X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/3 X-Sequence-Number: 4142 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"; > } > > 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.