useful recursive PHP functions

recursively ...

PHP Manual for

ocifetchstatement

(PHP 3>= 3.0.8, PHP 4 )

ocifetchstatement -- Fetch all rows of result data into an array

Description

int ocifetchstatement ( resource stmt, array &output [, int skip [, int maxrows [, int flags]]])

ocifetchstatement() fetches all the rows from a result into a user-defined array. ocifetchstatement() returns the number of rows fetched. skip is the number of initial rows to ignore when fetching the result (default value of 0, to start at the first line). maxrows is the number of rows to read, starting at the skip th row (Default to -1, meaning all the rows).

flags represents the available options for, which can be any combination of the following :

OCI_FETCHSTATEMENT_BY_ROW OCI_FETCHSTATEMENT_BY_COLUMN (default value) OCI_NUM OCI_ASSOC

Example 1. ocifetchstatement() example

<?php
/* OCIFetchStatement example mbritton at verinet dot com (990624) */

$conn = OCILogon("scott", "tiger");

$stmt = OCIParse($conn, "select * from emp");

OCIExecute($stmt);

$nrows = OCIFetchStatement($stmt, $results);
if (
$nrows > 0) {
   echo
"<table border=\"1\">\n";
   echo
"<tr>\n";
   while (list(
$key, $val) = each($results)) {
      echo
"<th>$key</th>\n";
   }
   echo
"</tr>\n";
   
   for (
$i = 0; $i < $nrows; $i++) {
      
reset($results);
      echo
"<tr>\n";
      while (
$column = each($results)) {   
         
$data = $column['value'];
         echo
"<td>$data[$i]</td>\n";
      }
      echo
"</tr>\n";
   }
   echo
"</table>\n";
} else {
   echo
"No data found<br />\n";
}      
echo
"$nrows Records Selected<br />\n";

OCIFreeStatement($stmt);
OCILogoff($conn);
?>

© 2012 lixlpixel