2

I am doing a query which fetches two fields.
I need each of those fields into a different array.
Will this rerun the query for each call or just re iterate over the result set?

$a= Laststatment->fetchAll(PDO::FETCH_COLUMN,0);
$b= Laststatment->fetchAll(PDO::FETCH_COLUMN,1);
Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
  • You could use fetchColumn(). See manual [link](http://www.php.net/manual/en/pdostatement.fetchcolumn.php) – oddtwelve Mar 13 '14 at 16:37

1 Answers1

0

Option 3: it will NOT reiterate over the resultset at all, as everything already has been fetched, and the second call will return an empty array (at least, here it does).

 $a = array();
 $b = array();
 while($r = $laststatement->fetch(PDO::FETCH_NUM)){
    $a[] = $r[0];
    $b[] = $r[1];
 }

That is: with MySQL there is no scrollable cursor, I have not attempted other database with a PDO::CURSOR_SCROLL possibility.

Wrikken
  • 69,272
  • 8
  • 97
  • 136