Connecting PHP with Oracle
PHP provides two extension modules with which we can connect to Oracle:
- The normal Oracle functions (ORA); and
- the Oracle Call-Interface functions (OCI).
OCI is frequently used. ORA doesn’t include support for CLOBs, BLOBs, BFILEs, ROWIDs, etc.
Here is a sample PHP script that uses OCI Extension module to connect Oracle.
<?php
$dbuser = “username”;
$dbpass = “password”;
$dbserver = “server”;
$c=OCILogon($dbuser, $dbpass, $dbserver);
if (!$c) {
$err = OCIError();
echo “Oracle Connect Error ” . $err[text];
}
OCILogoff($c);
?>
The following program fetches data from Oracle database using OCI :
<?php
$dbuser = “username”;
$dbpass = “password”;
$dbserver = “server”;
$c=OCILogon($dbuser, $dbpass, $dbserver);
if (!$c) {
$err = OCIError();
echo “Oracle Connect Error ” . $err[text];
}
$query =”SELECT * from student_details”;
$res= OCIParse($c,$query);
OCI_Execute($res, OCI_DEFAULT);
while(OCIFetch($res)){
$student_id = OCIResult($res, “STUDENT_ID”);
echo “Student Id” . $student_id;
}
OCILogoff($c);
?>