oci_fetch_arrayReturns the next row from a query as an associative or numeric array
&reftitle.description;
arrayoci_fetch_arrayresourcestatementintmode
Returns an array containing the next result-set row of a query.
Each array entry corresponds to a column of the row. This function
is typically called in a loop until it returns &false;, indicating
no more rows exist.
&oci.datatypes;
&reftitle.parameters;
statement
&oci.arg.statement.id;
mode
An optional second parameter can be any combination of the following
constants:
oci_fetch_array ModesConstantDescriptionOCI_BOTHReturns an array with both associative and numeric
indices. This is the same
as OCI_ASSOC
+ OCI_NUM and is the default
behavior.OCI_ASSOCReturns an associative array.OCI_NUMReturns a numeric array.OCI_RETURN_NULLSCreates elements for &null; fields. The element
values will be a PHP &null;.
OCI_RETURN_LOBSReturns the contents of LOBs instead of the LOB
descriptors.
The default mode is OCI_BOTH.
Use the addition operator "+" to specify more than
one mode at a time.
&reftitle.returnvalues;
Returns an array with associative and/or numeric indices. If there
are no more rows in the statement then
&false; is returned.
By default, LOB columns are returned as LOB descriptors.
DATE columns are returned as strings formatted
to the current date format. The default format can be changed with
Oracle environment variables such as NLS_LANG or
by a previously executed ALTER SESSION SET
NLS_DATE_FORMAT command.
Oracle's default, non-case sensitive column names will have
uppercase associative indices in the result array. Case-sensitive
column names will have array indices using the exact column case.
Use var_dump on the result array to verify the
appropriate case to use for each query.
&reftitle.examples;
oci_fetch_array with OCI_BOTH
\n";
echo $row[1] . " and " . $row['DEPARTMENT_NAME'] . " are the same \n";
}
oci_free_statement($stid);
oci_close($conn);
?>
]]>
oci_fetch_array with OCI_NUM
\n";
echo $row[1]->read(11) . " \n"; // this will output first 11 bytes from DESCRIPTION
}
// Output is:
// 1
// A very long
oci_free_statement($stid);
oci_close($conn);
?>
]]>
oci_fetch_array with OCI_ASSOC
\n";
echo $row['DESCRIPTION']->read(11) . " \n"; // this will output first 11 bytes from DESCRIPTION
}
// Output is:
// 1
// A very long
oci_free_statement($stid);
oci_close($conn);
?>
]]>
oci_fetch_array with OCI_RETURN_NULLS
string(1) "1"
}
*/
$stid = oci_parse($conn, 'SELECT 1, null FROM dual');
oci_execute($stid);
while (($row = oci_fetch_array ($stid, OCI_ASSOC+OCI_RETURN_NULLS))) { // Fetch NULLs
var_dump($row);
}
/*
The above code prints:
array(2) {
[1]=>
string(1) "1"
["NULL"]=>
NULL
}
*/
?>
]]>
oci_fetch_array with OCI_RETURN_LOBS
\n";
echo $row['DESCRIPTION'] . " \n"; // this contains all of DESCRIPTION
}
// Output is:
// 1
// A very long string
oci_free_statement($stid);
oci_close($conn);
?>
]]>
oci_fetch_array with case sensitive column names
\n"; // prints Chris
print $row['CITY'] . " \n"; // prints Melbourne
oci_free_statement($stid);
oci_close($conn);
?>
]]>
oci_fetch_array with columns having duplicate names
// string(9) "Australia"
// }
// To query a repeated column name, use an SQL column alias like "AS ctnm":
$sql = 'SELECT mycity.name AS ctnm, mycountry.name
FROM mycity, mycountry
WHERE mycity.id = mycountry.id';
$stid = oci_parse($conn, $sql);
oci_execute($stid);
$row = oci_fetch_array($stid, OCI_ASSOC);
var_dump($row);
// Output now contains both columns selected:
// array(2) {
// ["CTNM"]=>
// string(9) "Melbourne"
// ["NAME"]=>
// string(9) "Australia"
// }
oci_free_statement($stid);
oci_close($conn);
?>
]]>
oci_fetch_array with DATE columns
\n"; // prints 1997-06-14
oci_free_statement($stid);
oci_close($conn);
?>
]]>
oci_fetch_array with REF CURSOR
\n";
while ($row = oci_fetch_array($refcur, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "
\n";
}
echo "\n";
oci_free_statement($refcur);
oci_free_statement($stid);
oci_close($conn);
?>
]]>
oci_fetch_array with a LIMIT-like query
= :FIRST_ROW';
$first = 1; // start with the first row
$num = 5; // return 5 rows
$stid = oci_parse($conn, $limit_sql);
oci_bind_by_name($stid, ':FIRST_ROW', $first);
oci_bind_by_name($stid, ':NUM_ROWS', $num);
oci_execute($stid);
while (($row = oci_fetch_array($stid, OCI_ASSOC))) {
echo $row['CITY'] . " " . $row['POSTAL_CODE'] . " \n";
}
// Output is:
// Beijing 190518x
// Bern 3095x
// Bombay 490231x
// Geneva 1730x
// Hiroshima 6823x
oci_free_statement($stid);
oci_close($conn);
?>
]]>
&reftitle.notes;
Associative array indices need to be in uppercase for standard
Oracle columns that were created with case insensitive names.
&oci.use.setprefetch;
The function oci_fetch_array
is insignificantly slower than
oci_fetch_assoc
or oci_fetch_row, but is more flexible.
&reftitle.seealso;
oci_fetchoci_fetch_alloci_fetch_assococi_fetch_objectoci_fetch_rowoci_set_prefetch