OCIFetchStatement

OCIFetchStatement -- Fetch all rows of result data into an array.

Description

int OCIFetchStatement(int stmt, array &variable);

OCIFetchStatement() fetches all the rows from a result into a user-defined array. OCIFetchStatement() returns the number of rows fetched.

Example 1. OCIFetchStatement

  1 
  2 <?php
  3 /* OCIFetchStatement example mbritton@verinet.com (990624) */
  4 
  5 $conn = OCILogon("scott","tiger");
  6 
  7 $stmt = OCIParse($conn,"select * from emp");
  8 
  9 OCIExecute($stmt);
 10 
 11 $nrows = OCIFetchStatement($stmt,$results);
 12 if ( $nrows > 0 ) {
 13    print "<TABLE BORDER=\"1\">\n";
 14    print "<TR>\n";
 15    while ( list( $key, $val ) = each( $results ) ) {
 16       print "<TH>$key</TH>\n";
 17    }
 18    print "</TR>\n";
 19    
 20    for ( $i = 0; $i < $nrows; $i++ ) {
 21       reset($results);
 22       print "<TR>\n";
 23       while ( $column = each($results) ) {   
 24          $data = $column['value'];
 25          print "<TD>$data[$i]</TD>\n";
 26       }
 27       print "</TR>\n";
 28    }
 29    print "</TABLE>\n";
 30 } else {
 31    echo "No data found<BR>\n";
 32 }      
 33 print "$nrows Records Selected<BR>\n";
 34  
 35 OCIFreeStatement($stmt);
 36 OCILogoff($conn);
 37 
 38 ?>