oci_fetch_array Returns the next row from a query as an associative or numeric array &reftitle.description; arrayoci_fetch_array resourcestatement intmode 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: <function>oci_fetch_array</function> 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.
&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; <function>oci_fetch_array</function> with <constant>OCI_BOTH</constant> \n"; echo $row[1] . " and " . $row['DEPARTMENT_NAME'] . " are the same
\n"; } oci_free_statement($stid); oci_close($conn); ?> ]]>
<function>oci_fetch_array</function> with <constant>OCI_NUM</constant> \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); ?> ]]>
<function>oci_fetch_array</function> with <constant>OCI_ASSOC</constant> \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); ?> ]]>
<function>oci_fetch_array</function> with <constant>OCI_RETURN_NULLS</constant> 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 } */ ?> ]]> <function>oci_fetch_array</function> with <constant>OCI_RETURN_LOBS</constant> \n"; echo $row['DESCRIPTION'] . "
\n"; // this contains all of DESCRIPTION } // Output is: // 1 // A very long string oci_free_statement($stid); oci_close($conn); ?> ]]>
<function>oci_fetch_array</function> with case sensitive column names \n"; // prints Chris print $row['CITY'] . "
\n"; // prints Melbourne oci_free_statement($stid); oci_close($conn); ?> ]]>
<function>oci_fetch_array</function> 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); ?> ]]> <function>oci_fetch_array</function> with <literal>DATE</literal> columns \n"; // prints 1997-06-14 oci_free_statement($stid); oci_close($conn); ?> ]]> <function>oci_fetch_array</function> with <literal>REF CURSOR</literal> \n"; while ($row = oci_fetch_array($refcur, OCI_ASSOC+OCI_RETURN_NULLS)) { echo "\n"; foreach ($row as $item) { echo " ".($item !== null ? htmlentities($item, ENT_QUOTES) : " ")."\n"; } echo "\n"; } echo "\n"; oci_free_statement($refcur); oci_free_statement($stid); oci_close($conn); ?> ]]> <function>oci_fetch_array</function> with a <literal>LIMIT</literal>-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_fetch oci_fetch_all oci_fetch_assoc oci_fetch_object oci_fetch_row oci_set_prefetch