PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<ocifetchintoocifreecollection>
view the version of this page
Last updated: Sun, 02 May 2004

ocifetchstatement

(PHP 3>= 3.0.8, PHP 4 , PHP 5)

ocifetchstatement -- Estrae tutte le tuple in un array

Descrizione

int ocifetchstatement ( resource stmt, array & variable)

ocifetchstatement() estrae tutte le tuple da un risultato ponendole in un array definito dall'utente. ocifetchstatement() restituisce il numero di tuple estratte.

Esempio 1. Esempio di ocifetchstatement()

<?php
/* OCIFetchStatement example mbritton@verinet.com (990624) */

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

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

OCIExecute($stmt);

$nrows = OCIFetchStatement($stmt,$results);
if ( $nrows > 0 ) {
   print "<TABLE BORDER=\"1\">\n";
   print "<TR>\n";
   while ( list( $key, $val ) = each( $results ) ) {
      print "<TH>$key</TH>\n";
   }
   print "</TR>\n";
   
   for ( $i = 0; $i < $nrows; $i++ ) {
      reset($results);
      print "<TR>\n";
      while ( $column = each($results) ) {   
         $data = $column['value'];
         print "<TD>$data[$i]</TD>\n";
      }
      print "</TR>\n";
   }
   print "</TABLE>\n";
} else {
   echo "No data found<BR>\n";
}      
print "$nrows Records Selected<BR>\n";
 
OCIFreeStatement($stmt);
OCILogoff($conn);
?>


add a note add a note User Contributed Notes
ocifetchstatement
david at boeke dot com
16-Dec-2003 04:17
The Skip and MaxRows parameters were not added until version 4.2.1.
Previous versions of php used this syntax:

           int ocifetchstatement ( resource stmt, array &output)

The function also took a third parameter that was not documented.  ( I assume that it was a flag)
adelac05 at sprintspectrum dot com
12-Mar-2003 10:40
One thing I found with this:

If you have two tables with the same column names, you will run into problems when displaying them, i.e:

$sql = "select a.name, b.name, c.phone
from table1 a, table2 b, table3 c";

php will overwrite the a.name display cell with the b.name value.  So you wanted three cells to display and you are only getting two.  i.e.

What you wanted:

----------------------------------------
| Bob          | Jones    | 555-555-5555 |
----------------------------------------

What you got:

-----------------------------------------
| Jones        | 555-555-5555 |              |
-----------------------------------------

Resolution:  rename your table column names as they come in.

$sql = "select a.name, b.name AS NAME2, c.phone
from table1 a, table2 b, table3 c";
lzilber at hotmail dot com
03-Aug-2001 08:19
Similar to the closed bug #9520 reported by g.giunta@libero.it (it did not seem obvious to me):<br>
After a call to OCIFetchStatement, functions OCIColumnName, OCIColumnSize, OCIColumnType, ... will NOT work anymore on the fetched statement.<br>
Explanation (thies@php.net): "...after a cursor is completly read (which is what fechstatement does) this information is no longer valid."
</p>
aries at bsd dot hu
29-Dec-2000 08:41
Don't forget: you must use capital letters as column name.
waycool at audioload dot com
31-Oct-1999 07:44
Watch out for select statements which have columns with the same name (e.g. select a.name, b.name from ...) because the later results will wipe out the previous $data["name"] values. One way to get around this is to use aliases (e.g. select a.name as a_name, b.name as b_name ...)

<ocifetchintoocifreecollection>
 Last updated: Sun, 02 May 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2004 The PHP Group
All rights reserved.
This mirror generously provided by: Italia OnLine S.p.a.
Last updated: Fri May 21 04:11:23 2004 CEST