#native_company# #native_desc#
#native_cta#

Oracle with PHP: a Developers View Page 2

By Rajeev Ranjan Rakesh
on October 17, 2008

$conn = oci_connect($dbuser,$dbpassword, ??CONN_STRING??);

$sql = "SELECT??*??FROM??EMPLOYEE_TABLE";

Here $sql stores the sql statement which is to be executed:

$stmt??=??oci_parse($conn,??$sql);

oci_parse() function prepares the statement for execution. It takes the connection identifier and the sql query as a parameter and returns a statement handler.

oci_execute($stmt,??OCI_DEFAULT);

oci_execute() function executes the parsed statement. This function can have two parameters. The first one is the valid OCI statement identifier and the second one is the mode (option parameter). By default OCI_COMMIT_ON_SUCCESS.
Note: If you don’t want statements to be committed automatically, you should specify OCI_DEFAULT as mode.

while($result =oci_fetch_array($stmt)) {	
	echo $result[??EMPLOYEE_NAME??] . "<br>";	
}

The statement above stores the result of oci_fetch_array($stmt) in the variable $result. oci_fetch_array() returns an array. The second parameter is optional for this function and can have values like OCI_BOTH, OCI_ASSOC, OCI_NUM depending on the type of array that is required. Once the array is returned and stored in the variable $result, we display the Employee name from the selected columns.

oci_close($conn);
    

This function is used to close the connection to the Oracle database.
This completes the explanation of the sample code that is used to connect and perform operations on the Oracle database using PHP??s ADOdb abstract library.
Join us next week when we delve into the ADOdb library and continue our discussion on using Oracle and PHP!