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>
oci_fetch_array
(PHP 5, PECL oci8:1.1-1.2.4)
oci_fetch_array — Lit une ligne d'un résultat Oracle sous forme de tableau
Description
Retourne un tableau, qui correspond à la prochaine ligne du résultat.
Pour plus de détails sur le mapping des types de données effectué par le driver oci8, lisez les types de données supportés par le driver
Il faut mentionner ici que oci_fetch_array() n'est pas significativement plus lente que oci_fetch_row(), mais bien plus pratique.
Liste de paramètres
- statement
-
Un identifiant de requête OCI valide.
- statement
-
Le paramètre optionnel mode peut être la combinaison des constantes suivantes :
- OCI_BOTH - retourne une tableau, indexé numériquement et avec les noms de colonnes. Identique à OCI_ASSOC + OCI_NUM). C'est le comportement par défaut.
- OCI_ASSOC - retourne un tableau associatif. C'est le même comportement que celui de la fonction oci_fetch_assoc().
- OCI_NUM - retourne un tableau indexé numériquement, C'est le même comportement que celui de la fonction oci_fetch_row().
- OCI_RETURN_NULLS - Crée des éléments vides pour les valeurs NULL.
- OCI_RETURN_LOBS - Retourne la valeur du LOB.
Valeurs de retour
Retourne un tableau avec des indices associatifs et numériques, ou FALSE s'il n'y a plus de ligne dans la requête statement .
Note: Cette fonction définit les champs NULL à la valeur PHP NULL.
Note: Oracle retourne tous les noms de champs en majuscules, et les noms des index du tableau résultant seront donc aussi en majuscules.
Exemples
Exemple #1 Exemple avec oci_fetch_array() avec OCI_BOTH
<?php
$connection = oci_connect("apelsin", "kanistra");
$query = "SELECT id, name FROM fruits";
$statement = oci_parse ($connection, $query);
oci_execute ($statement);
while ($row = oci_fetch_array ($statement, OCI_BOTH)) {
echo $row[0]." and ".$row['ID']." sont identiques<br>";
echo $row[1]." and ".$row['NAME']." sont identiques<br>";
}
?>
Exemple #2 Exemple avec oci_fetch_array() avec OCI_NUM
<?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_NUM)) {
echo $row[0]."<br>";
echo $row[1]."<br>";
echo $row[2]->read(100)."<br>"; //Affiche les 100 premiers bytes du LOB
}
?>
Exemple #3 Exemple avec oci_fetch_array() avec OCI_ASSOC
<?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_ASSOC)) {
echo $row['ID']."<br>";
echo $row['NAME']."<br>";
echo $row['LOB_FIELD']."<br>"; //Affiche "Object id #1"
}
?>
Exemple #4 Exemple avec oci_fetch_array() avec OCI_RETURN_LOBS
<?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_NUM+OCI_RETURN_LOBS))) {
echo $row[0]."<br>";
echo $row[1]."<br>";
echo $row['LOB_FIELD']."<br>"; //Affiche le contenu du LOB
}
?>
oci_fetch_array
18-Jul-2006 05:14
18-Apr-2006 01: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...
27-Jan-2006 08: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.
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;
}
?>
20-May-2005 07: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;
}
?>
09-Aug-2004 05: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.
