downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

oci_fetch_assoc> <oci_fetch_all
Last updated: Fri, 30 Oct 2009

view this page in

oci_fetch_array

(PHP 5, PECL oci8 >= 1.1.0)

oci_fetch_arrayLiefert die nächste Zeile der Ergebnisdaten als assoziatives und/oder numerisches Array

Beschreibung

array oci_fetch_array ( resource $statement [, int $mode ] )

Liefert ein Array, welches mit der nächsten Ergebniszeile übereinstimmt.

Für Details zur vom OCI8-Treiber durchgeführten Umsetzung von Datentypen siehe die vom Treiber unterstützen Datentypen.

Es sollte hier noch erwähnt sein, das oci_fetch_array() nur unwesentlich langsamer als oci_fetch_row(), dafür aber viel handlicher ist.

Parameter-Liste

statement

Ein Zeiger auf eine gültige OCI-Anweisung.

mode

Der optionale zweite Parameter kann eine beliebige Kombination aus dem folgenden Konstanten sein:

  • OCI_BOTH - liefert ein Array sowohl mit assoziativen als auch numerischem Index (gleichzusetzen mit OCI_ASSOC + OCI_NUM). Dieses ist das Standardverhalten.
  • OCI_ASSOC - liefert ein assiziatives Array (funktioniert wie oci_fetch_assoc()).
  • OCI_NUM - liefert ein indiziertes Array (funktioniert wie oci_fetch_row()).
  • OCI_RETURN_NULLS - erstellt leere Elemente für NULL-Felder.
  • OCI_RETURN_LOBS - liefert den Wert eines LOB-Deskriptors.

Standard für mode ist OCI_BOTH.

Rückgabewerte

Liefert ein Array sowohl mit assoziativem wie numerischem Index oder FALSE, wenn es keine weiteren Zeilen für das statement gibt.

Hinweis: Diese Funktion setzt NULL-Felder auf den PHP Wert-NULL.

Hinweis: Oracle liefert alle Feldnamen in Großschrift zurück, daher sind auch die assoziativen Indizes im Ergebnisarray in Großschrift.

Beispiele

Beispiel #1 oci_fetch_array() mit OCI_BOTH-Beispiel

<?php
$connection 
oci_connect("apelsin""kanistra");

$query "SELECT id, name FROM fruechte";

$statement oci_parse ($connection$query);
oci_execute ($statement);

while (
$row oci_fetch_array ($statementOCI_BOTH)) {
    echo 
$row[0]." und ".$row['ID']." ist gleich<br>";
    echo 
$row[1]." und ".$row['NAME']." ist gleich<br>";
}
?>

Beispiel #2 oci_fetch_array() mit OCI_NUM-Beispiel

<?php
$connection 
oci_connect("user""password");

$query "SELECT id, name, lob_field FROM fruechte";

$statement oci_parse ($connection$query);
oci_execute ($statement);

while (
$row oci_fetch_array ($statementOCI_NUM)) {
    echo 
$row[0]."<br>";
    echo 
$row[1]."<br>";
    echo 
$row[2]->read(100)."<br>";  // dies gibt die ersten 100 Bytes des LOBs aus
}
?>

Beispiel #3 oci_fetch_array() mit OCI_ASSOC-Beispiel

<?php
$connection 
oci_connect("user""password");

$query "SELECT id, name, lob_field FROM fruechte";

$statement oci_parse ($connection$query);
oci_execute ($statement);

while (
$row oci_fetch_array ($statementOCI_ASSOC)) {
    echo 
$row['ID']."<br>";
    echo 
$row['NAME']."<br>";
    echo 
$row['LOB_FIELD']."<br>";  // dies gibt "Object id #1" aus
}
?>

Beispiel #4 oci_fetch_array() mit OCI_RETURN_LOBS-Beispiel

<?php
$connection 
oci_connect("user""password");

$query "SELECT id, name, lob_field FROM fruechte";

$statement oci_parse ($connection$query);
oci_execute ($statement);

while (
$row oci_fetch_array ($statement, (OCI_NUM+OCI_RETURN_LOBS))) {
    echo 
$row[0]."<br>";
    echo 
$row[1]."<br>";
    echo 
$row['LOB_FIELD']."<br>";  // dies gibt den Inhalt des LOBs aus
}
?>

Siehe auch



oci_fetch_assoc> <oci_fetch_all
Last updated: Fri, 30 Oct 2009
 
add a note add a note User Contributed Notes
oci_fetch_array
badr at arabiadata dot com
18-Jul-2006 12:14
generating dynamic drop down list
<SELECT name="reason" id="vacation_code">
<OPTION value=0 selected>Choose </OPTION>
<?php
$query2
= "SELECT IN_NAME, IN_CODE FROM HR_IN_REASON ";
$statement2 = oci_parse ($conn, $query2);
oci_execute ($statement2);
while (
$row = oci_fetch_array ($statement2, OCI_NUM)) {
 
?>
                  <option value="<?  echo $row[1]; ?>"> <? echo $row[0] ?> </option>
                  <? }
?>
                </select>
antonchanning at gmail dot com
18-Apr-2006 08:59
As Robert Hicks mentioned back in August 2004 there is an error in examples 3 and 4 of this page.  The error in example 3 is what dwhitaker and stry_cat address in their notes of 20 May 2005 and 9 June 2005 respectively.

The correct form of example 4 should read:

<?php
$connection
= oci_connect("user", "password");

$query = "SELECT id, name, lob_field FROM fruits";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);

while (
$row = oci_fetch_array ($statement, OCI_RETURN_LOBS)) {
   echo
$row[0]."<br>";
   echo
$row[1]."<br>";
   echo
$row['LOB_FIELD']."<br>"//this will output LOB's content
}
?>

This really should be corrected in the actual documentation...
stry_cat at yahoo dot com
27-Jan-2006 04:29
If you want to get both nulls and an assoc array, you have to ADD the values like this:

$row = oci_fetch_array($stmt, OCI_RETURN_NULLS + OCI_ASSOC);

This really should be noted in the text of the manual.
09-Jun-2005 03:13
OCI_BOTH is the default.

If you just need to return all fields, you can leave out OCI_NUM & OCI_ASSOC.

EXAMPLE:

<?php
$connection
= ocilogon("user", "password", "dbname");

$query = "SELECT id, name, lob_field FROM fruits";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);

while (
$row = oci_fetch_array ($statement)) {
  
$id = $row['ID'];
  
$name = $row['NAME'];
  
$lob_field = $row['LOB_FIELD'];

   echo
$id.' '.$name.' '.$lob_field;

}
?>
dwhitaker at dfwairport dot com
20-May-2005 02:39
Example 3 above is incorrect...

OCI_NUM should be OCI_ASSOC

So it should read something like this:

<?php
$connection
= ocilogon("user", "password", "dbname");

$query = "SELECT id, name, lob_field FROM fruits";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);

while (
$row = oci_fetch_array ($statement, OCI_ASSOC)) {
  
$id = $row['ID'];
  
$name = $row['NAME'];
  
$lob_field = $row['LOB_FIELD'];

   echo
$id.' '.$name.' '.$lob_field;

}
?>
robert dot hicks at gmail dot com
10-Aug-2004 12:57
OCI_NUM should be changed in the various scripts to the appropriate call to the OCI_*. For example the script to show the OCI_ASSOC call still has OCI_NUMS in it.

oci_fetch_assoc> <oci_fetch_all
Last updated: Fri, 30 Oct 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites