February 24, 2021
Hot Topics:

Combining an Oracle Database with PHP to Manage Data

  • By Deepak Vohra
  • Send Email »
  • More Articles »

PHP is the one of the most commonly used scripting languages. The Oracle database is the most commonly used commercial database (according to Gartner, Inc.). PHP and the Oracle database make a great combination suitable for developing web applications. The PHP Oracle extension may be used to connect to Oracle database 10g, 9i, and 8i by using the Oracle Call Interface (OCI). The PHP extension for the Oracle database is included in the PHP 5 installation. The Oracle PHP extension provides features such as connection caching (pooling), privileged connections using external credentials, statement caching, and row pre-fetching. In this article, you will install PHP's OCI extension for Oracle database, decide which connection method to use, create a database, and retrieve data from that database and display it in a table.

Installing the Oracle Extension

First, install PHP 5 and Apache HTTP Server 2. Add C:/PHP, the directory in which PHP 5 is installed, to the PATH environment variable. Rename the php.ini-recommended.configuration file in the C:/PHP directory to php.ini. The example application in this article will store and fetch data from Oracle database 10g. Therefore, enable the Oracle database extension in php.ini configuration file by removing the ';' from the following line.


Set the extension directory directive in php.ini to the directory containing the PHP extensions.

extension_dir = "./ext"

Next, configure Apache HTTP Server 2 with PHP 5 by adding the following configuration directives to <Apache2>/conf/httpd.conf file; <Apache2> being the directory in which Apache 2 web server is installed.

# For PHP 5
LoadModule php5_module "C:/PHP/php5apache2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "C:/PHP/"

You need to restart the Apache 2 server. Install the Oracle database 10g, including the sample schemas. The OCI8 extension provides various configuration directives for the php.ini file. Some of the commonly used configuration directives are discussed in Table 1.

Table 1: OCI8 Configuration Directives

Directive Description Default Value
oci8.max_persistent Specifies the maximum number of persistent OCI8 connections per process.


The default value specifies no limit.

oci8.persistent_timeout Specifies the maximum length of time (in seconds) that a process may maintain an idle persistent connection.


The default value indicates that the idle persistent connections do not timeout.

oci8.ping_interval Specifies the length of time (in seconds) between pings for persistent connections. If set to 0, persistent connections are pinged every time they are reused. Setting the value to -1 disables pings; this will make oci_pconnect() operate at the highest frequency, but does not detect faulty connections. 60
oci8.statement_cache_size Specifies number of statements to cache. Statement caching improves performance, but memory load also increases. Setting the value to 0 disables statement caching. 20
oci8.default_prefetch Specifies the default number of rows that will be pre-fetched after a statement is run; this improves performance, but memory load also increases. 10
oci8.privileged_connect Enables privileged connections using external credentials.


By default, privileged connections are not enabled.

Page 1 of 5

This article was originally published on October 5, 2007

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date