Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

oci_fetch_row(3) [php man page]

OCI_FETCH_ROW(3)														  OCI_FETCH_ROW(3)

oci_fetch_row - Returns the next row from a query as a numeric array

SYNOPSIS
array oci_fetch_row (resource $statement) DESCRIPTION
Returns a numerically indexed 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. Calling oci_fetch_row(3) is identical to calling oci_fetch_array(3) with OCI_NUM + OCI_RETURN_NULLS. PARAMETERS
o $statement -A valid OCI8 statement identifier created by oci_parse(3) and executed by oci_execute(3), or a REF CURSOR statement identifier. RETURN VALUES
Returns a numerically indexed array. If there are no more rows in the $statement then FALSE is returned. EXAMPLES
Example #1 oci_fetch_row(3) Example <?php $conn = oci_connect('hr', 'welcome', 'localhost/XE'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $stid = oci_parse($conn, 'SELECT department_id, department_name FROM departments'); oci_execute($stid); while (($row = oci_fetch_row($stid)) != false) { echo $row[0] . " " . $row[1] . "<br> "; } oci_free_statement($stid); oci_close($conn); ?> NOTES
Note See oci_fetch_array(3) for more examples of fetching rows. SEE ALSO
oci_fetch(3), oci_fetch_all(3), oci_fetch_array(3), oci_fetch_assoc(3), oci_fetch_object(3). PHP Documentation Group OCI_FETCH_ROW(3)

Check Out this Related Man Page

OCI_GET_IMPLICIT_RESULTSET(3)											     OCI_GET_IMPLICIT_RESULTSET(3)

oci_get_implicit_resultset  -  Returns	the  next  child statement resource from a parent statement resource that has Oracle Database 12c Implicit
Result Sets

SYNOPSIS
resource oci_get_implicit_resultset (resource $statement) DESCRIPTION
Used to fetch consectutive sets of query results after the execution of a stored or anonymous Oracle PL/SQL block where that block returns query results with Oracle's DBMS_SQL.RETURN_RESULT PL/SQL function. This allows PL/SQL blocks to easily return query results. The child statement can be used with any of the OCI8 fetching functions: oci_fetch(3), oci_fetch_all(3), oci_fetch_array(3), oci_fetch_object(3), oci_fetch_assoc(3) or oci_fetch_row(3) Child statements inherit their parent statement's prefetch value, or it can be explicitly set with oci_set_prefetch(3). PARAMETERS
o $statement -A valid OCI8 statement identifier created by oci_parse(3) and executed by oci_execute(3). The statement identifier may or may not be associated with a SQL statement that returns Implicit Result Sets. RETURN VALUES
Returns a statement handle for the next child statement available on $statement. Returns FALSE when child statements do not exist, or all child statements have been returned by previous calls to oci_get_implicit_resultset(3). EXAMPLES
Example #1 Fetching Implicit Result Sets in a loop <?php $conn = oci_connect('hr', 'welcome', 'localhost/pdborcl'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $sql = 'DECLARE c1 SYS_REFCURSOR; BEGIN OPEN c1 FOR SELECT city, postal_code FROM locations WHERE ROWNUM < 4 ORDER BY city; DBMS_SQL.RETURN_RESULT(c1); OPEN c1 FOR SELECT country_id FROM locations WHERE ROWNUM < 4 ORDER BY city; DBMS_SQL.RETURN_RESULT(c1); END;'; $stid = oci_parse($conn, $sql); oci_execute($stid); while (($stid_c = oci_get_implicit_resultset($stid))) { echo "<h2>New Implicit Result Set:</h2> "; echo "<table> "; while (($row = oci_fetch_array($stid_c, OCI_ASSOC+OCI_RETURN_NULLS)) != false) { echo "<tr> "; foreach ($row as $item) { echo " <td>".($item!==null?htmlentities($item, ENT_QUOTES|ENT_SUBSTITUTE):"&nbsp;")."</td> "; } echo "</tr> "; } echo "</table> "; } // Output is: // New Implicit Result Set: // Beijing 190518 // Bern 3095 // Bombay 490231 // New Implicit Result Set: // CN // CH // IN oci_free_statement($stid); oci_close($conn); ?> Example #2 Getting child statement handles individually <?php $conn = oci_connect('hr', 'welcome', 'localhost/pdborcl'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $sql = 'DECLARE c1 SYS_REFCURSOR; BEGIN OPEN c1 FOR SELECT city, postal_code FROM locations WHERE ROWNUM < 4 ORDER BY city; DBMS_SQL.RETURN_RESULT(c1); OPEN c1 FOR SELECT country_id FROM locations WHERE ROWNUM < 4 ORDER BY city; DBMS_SQL.RETURN_RESULT(c1); END;'; $stid = oci_parse($conn, $sql); oci_execute($stid); $stid_1 = oci_get_implicit_resultset($stid); $stid_2 = oci_get_implicit_resultset($stid); $row = oci_fetch_array($stid_1, OCI_ASSOC+OCI_RETURN_NULLS); var_dump($row); $row = oci_fetch_array($stid_2, OCI_ASSOC+OCI_RETURN_NULLS); var_dump($row); $row = oci_fetch_array($stid_1, OCI_ASSOC+OCI_RETURN_NULLS); var_dump($row); $row = oci_fetch_array($stid_2, OCI_ASSOC+OCI_RETURN_NULLS); var_dump($row); // Output is: // array(2) { // ["CITY"]=> // string(7) "Beijing" // ["POSTAL_CODE"]=> // string(6) "190518" // } // array(1) { // ["COUNTRY_ID"]=> // string(2) "CN" // } // array(2) { // ["CITY"]=> // string(4) "Bern" // ["POSTAL_CODE"]=> // string(4) "3095" // } // array(1) { // ["COUNTRY_ID"]=> // string(2) "CH" // } oci_free_statement($stid); oci_close($conn); ?> Example #3 Explicitly setting the Prefetch Count <?php $conn = oci_connect('hr', 'welcome', 'localhost/pdborcl'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $sql = 'DECLARE c1 SYS_REFCURSOR; BEGIN OPEN c1 FOR SELECT city, postal_code FROM locations ORDER BY city; DBMS_SQL.RETURN_RESULT(c1); END;'; $stid = oci_parse($conn, $sql); oci_execute($stid); $stid_c = oci_get_implicit_resultset($stid); oci_set_prefetch($stid_c, 200); // Set the prefetch before fetching from the child statement echo "<table> "; while (($row = oci_fetch_array($stid_c, OCI_ASSOC+OCI_RETURN_NULLS)) != false) { echo "<tr> "; foreach ($row as $item) { echo " <td>".($item!==null?htmlentities($item, ENT_QUOTES|ENT_SUBSTITUTE):"&nbsp;")."</td> "; } echo "</tr> "; } echo "</table> "; oci_free_statement($stid); oci_close($conn); ?> Example #4 Implicit Result Set example without using oci_get_implicit_resultset(3) All results from all queries are returned consecutively. <?php $conn = oci_connect('hr', 'welcome', 'localhost/pdborcl'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $sql = 'DECLARE c1 SYS_REFCURSOR; BEGIN OPEN c1 FOR SELECT city, postal_code FROM locations WHERE ROWNUM < 4 ORDER BY city; DBMS_SQL.RETURN_RESULT(c1); OPEN c1 FOR SELECT country_id FROM locations WHERE ROWNUM < 4 ORDER BY city; DBMS_SQL.RETURN_RESULT(c1); END;'; $stid = oci_parse($conn, $sql); oci_execute($stid); // Note: oci_fetch_all and oci_fetch() cannot be used in this manner echo "<table> "; while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) { echo "<tr> "; foreach ($row as $item) { echo " <td>".($item!==null?htmlentities($item, ENT_QUOTES|ENT_SUBSTITUTE):"&nbsp;")."</td> "; } echo "</tr> "; } echo "</table> "; // Output is: // Beijing 190518 // Bern 3095 // Bombay 490231 // CN // CH // IN oci_free_statement($stid); oci_close($conn); ?> NOTES
Note For queries returning a large number of rows, performance can be significantly improved by increasing oci8.default_prefetch or using oci_set_prefetch(3). PHP Documentation Group OCI_GET_IMPLICIT_RESULTSET(3)
Man Page