Re: Unbuffered queries - Mailing list pgsql-php

From Mark Kirkwood
Subject Re: Unbuffered queries
Date
Msg-id 52D25955.4050909@catalyst.net.nz
Whole thread Raw
In response to Re: Unbuffered queries  (Eric Chamberlain <eric.chamberlain@hotmail.com>)
List pgsql-php
On 09/01/14 18:33, Eric Chamberlain wrote:
> Correct. I ended up limiting the number of records I query at a time.
> I'm not sure how much of the thread has been e-mailed to you but I have
> an example that shows the method in which I was able to query N number
> of records every iteration.
>

Unfortunately I don't seem to have seen that message. However that
reminds me that for completeness I should really show an example
fetching >1 row at a time in PDO (pgbench schema again):

     $fetch_num = 100;
     $cursql = "DECLARE cur1 CURSOR FOR SELECT * FROM pgbench_accounts
WHERE bid = ?";
     $sql    = "FETCH $fetch_num FROM cur1";

     $dbh->beginTransaction();
     $curstmt = $dbh->prepare($cursql);
     $curstmt->execute(array(rand(0, 100)));

     for (;;) {
         $stmt = $dbh->prepare($sql);
         $stmt->execute();
         $rowarray = $stmt->fetchAll(PDO::FETCH_ASSOC);
         if ($rowarray) {
             foreach ($rowarray as $row) {
                 print "... " . $row['aid'] . " " . $row['bid'] . "\n";
             }
         } else {
             break;
         }
     }


Regards

Mark


pgsql-php by date:

Previous
From: Eric Chamberlain
Date:
Subject: Re: Unbuffered queries
Next
From: Archana K N
Date:
Subject: UPDATE (SELECT ) is not working................