PHP – Oracle Connectivity
Introductions –
Using PHP we can connect many databases like MySQL, Postgresql, DB2, Oracle and SQL server very easily. Now this article provides the information about database connectivity to Oracle using PHP…
PHP Oracle functions allow you to access Oracle 10, Oracle 9, Oracle 8 and Oracle 7 databases using the Oracle Call Interface (OCI). They support binding of PHP variables to Oracle placeholders, have full LOB, FILE and ROWID support, and allow you to use user-supplied define variables.
Configuration part in windows php_oci8.dll is the connectivity dll in windows environment. In Linux we can compile php with oracle module…
Once the configuration completes you will be able to see this configuration when you execure –
URL = http://localhost/phpinfo.php
<?php
phpinfo();
?>
** Basic example to connect ORACLE database and execute query –
root@arunbagul:~# cat /var/www/php_oracle.php
<?php
$conn = oci_connect(‘hr’, ‘hr’, ‘orcl’);
if (!$conn) {
$e = oci_error();
print htmlentities($e[‘message’]);
exit;
}
$query = ‘SELECT * FROM DEPARTMENTS’;
$stid = oci_parse($conn, $query);
if (!$stid) {
$e = oci_error($conn);
print htmlentities($e[‘message’]);
exit;
}
$r = oci_execute($stid, OCI_DEFAULT);
if (!$r) {
$e = oci_error($stid);
echo htmlentities($e[‘message’]);
exit;
}
root@arunbagul:~#
Other way to connect to oracle using simple Oracle functions. But these functions are deprecated. Now a day’s oci8 functions are in used.
Cheers,
Santhosh Tirunahari