oci_fetch_array

PHP 5, PHP 7, PHP 8, PECL OCI8 >= 1.1.0
oci_fetch_array - Returns the next row from a query as an associative or numeric array
Manual
Code Examples

oci_fetch_array( resource$statement, [int$mode = OCI_BOTH | OCI_RETURN_NULLS] ): array|false

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.

If statement corresponds to a PL/SQL block returning Oracle Database Implicit Result Sets, then rows from all sets are consecutively fetched. If statement is returned by oci_get_implicit_resultset, then only the subset of rows for one child query are returned.

For details on the data type mapping performed by the OCI8 extension, see the datatypes supported by the driver

Parameters

statement

A valid OCI8 statement identifier created by oci_parse and executed by oci_execute, or a REF CURSOR statement identifier.

Can also be a statement identifier returned by oci_get_implicit_resultset.

mode

An optional second parameter can be any combination of the following constants:

oci_fetch_array Modes
Constant Description
OCI_BOTH Returns an array with both associative and numeric indices. This is the same as OCI_ASSOC + OCI_NUM and is the default behavior.
OCI_ASSOC Returns an associative array.
OCI_NUM Returns a numeric array.
OCI_RETURN_NULLS Creates elements for null fields. The element values will be a PHP null.
OCI_RETURN_LOBS Returns 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.

Return Values

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.

The table name is not included in the array index. If your query contains two different columns with the same name, use OCI_NUM or add a column alias to the query to ensure name uniqueness, see example #7. Otherwise only one column will be returned via PHP.

Notes

Note:

Associative array indices need to be in uppercase for standard Oracle columns that were created with case insensitive names.

Note:

For queries returning a large number of rows, performance can be significantly improved by increasing oci8.default_prefetch or using oci_set_prefetch.

Note:

The function oci_fetch_array is insignificantly slower than oci_fetch_assoc or oci_fetch_row, but is more flexible.

Related Functions

Example of oci_fetch_array

Show all examples for oci_fetch_array

PHP Version:


Function oci_fetch_array:

Oracle OCI8 Functions

Most used PHP functions