Connecting PHP to Oracle Database 10g

PHP is very well compatible with MySQL. But I found connecting PHP to Oracle is a pain. In my current job, my employer uses Oracle Version 10g. It uses an oracle server and an oracle client 10g software to connect to the server. I tried several ways to connect to the oracle database server using PHP.


Each time WAMP generated the following error

[code]PHP Startup: Unable to load dynamic library ‘e:/wamp/bin/php/php5.4.3/ext/phppdooci.dll’ – The specified procedure could not be found.[/code]

Its because we need to find a compatible version of OCI8.dll supplied by oracle to connect to oracle server. The following configurations are compatible and worked for me well.
Finally I was successful. The simplest way to connect to the Oracle database using PHP and extracting data from database is as follows

Assuming you are using a Windows Operating System

  1. Install latest WAMP Server2 for windows
  2. Download and install separate PHP5.2.6 from WAMP website
  3. Download and install APACHE Version 2.2.2 from WAMP website
  4. Now left click on the WAMP Server icon running in your taskbar.
  5. Go to Apache->Version->2.2.2


  1. Go to PHP->Version->5.2.6


  1. Activate both PHPPDO and PHPPDO_OCI extensions of PHP from WAMP server control panel as shown bellow.php-oracle-activate-oracle-pdo-extension

  2. Restart all services of WAMP

Now WAMP should not generate any error and the following code should execute

 $stmt = $pdo->prepare("select distinct i.part_no, i.description from inventory_part");  
 $arr = array();  
 while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {  
 $arr[] = $row;  
 $json_response = json_encode($arr);  
 echo $json_response;