User's Manual
Connecting to the Database
Beta Draft Getting Connected 3-5
The oci_parse() function prepares the query for execution, and is supplied the
connection identifier and query string as the first and second parameters,
respectively. The oci_parse() function returns a statement identifier needed to
execute the query and fetch the resulting data rows, otherwise it returns FALSE on
error.
The oci_execute() function executes the statement associated with the
statement identifier provided in the first parameter. The second parameter
specifies the execution mode. OCI_DEFAULT is used to indicate you do not want
to statements to be committed automatically. The default execution mode is
OCI_COMMIT_ON_SUCCESS. The oci_execute() function returns TRUE on
success, otherwise it returns FALSE.
A while loop is used to fetch all the rows for the query executed. The
oci_fetch_array() returns the next row from the result data, otherwise it
returns FALSE if there are no more rows. The second parameter to
oci_fetch_array() of OCI_RETURN_NULLS indicates that NULL database
fields will be returned as PHP NULL values.
Each row of data is return as an associative or numeric array of column values.
The code uses a PHP foreach construct to loop through the array and print each
column value in a HTML table cell, inside a table row element. If the item value is
NULL then a non-breaking space is printed, otherwise the item value is printed.
2. To test the changes made to $HOME/public_html/chap3/anyco.php, save the
modified anyco.php file and in a browser window enter the following URL:
http://localhost/~<username>/chap3/anyco.php
The page returned in the browser window should resemble the following page:
If you wanted to query the EMPLOYEES data you could change the query in the
do_query() function call to:
do_query($conn, 'SELECT * FROM EMPLOYEES');
Other Ways to Connect
In some applications using a persistent connection improves performance by
removing the need to reconnect each time the script is called. Depending on your
Apache configuration, this may cause a number of database connections to remain