Connecting PHP to Oracle Database 10g
In this post we will show you Connecting PHP to Oracle Database 10g, hear for Connecting PHP to Oracle Database 10g we will give you demo and example for implement.
PHP is very good compatible with MySQL. But we found connecting PHP to Oracle is a pain. In this current job, over employer uses Oracle Version 10g. It uses an oracle server and an oracle client 10g software to connect to the server. we tried several ways to connect to the oracle database server using PHP.
Each time WAMP generated the following error
[PHP]PHP Startup: Unable to load dynamic library “e:/wamp/bin/php/php5.4.3/ext/phppdooci.dll” – The specified procedure could not be found.[/PHP]
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 we 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
- Install latest WAMP Server2 for windows
- Download and install separate PHP5.2.6 from WAMP website
- Download and install APACHE Version 2.2.2 from WAMP website
- Now left click on the WAMP Server icon running in your taskbar.
- Go to Apache->Version->2.2.2
Go to PHP->Version->5.2.6
Activate both PHPPDO and PHPPDO_OCI extensions of PHP from WAMP server control panel as shown bellow.php
Restart all services of WAMP/LAMP/XAMP
Now WAMP/LAMP/XAMP should not generate any error and the following code should execute
<?php $sql_pdo = new PDO('oci:dbname=YOUR_ORACLE_DB_NAME', 'ORACLE_DB_USERNAME', 'ORACLE_DB_PASSWORD'); $sql_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $sql_pdo->prepare("select distinct i.part_no, i.description from inventory_part"); $stmt->execute(); $arr = array(); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $arr[] = $row; } $json_response = json_encode($arr); echo $json_response; ?>
Hope this code and post will helped you for implement Connecting PHP to Oracle Database 10g. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org
The image is broken
need help and really appreciate it if it would come back to normal
thank’s in advance