How to Connect PHP 5 with Oracle 10G in WindowsXP

· Installe the WampServer 2.0 (for running php )

· Installe the Oracle 10g

WampServer 2.0

WampServer 2.0


Note: There is no need to change the port address of wamp and oracle.

Then the following things to be done :

For the PHP part :

1. Search for php.ini file inside wamp(folder)

There will be two files found in the search result

(according to my Computer hardisk :

C:\wamp\bin\php\php5.2.6\php.ini
C:\wamp\bin\apache\apache2.2.8\bin\php.ini )

2. Now open the php.ini file in notepad

3. Find this :

extension=php_oci8.dll

extension=php_pdo_oci.dll

extension=php_pdo_oci8.dll

And remove the ; (semicolon ) if present before the extension word .

Before :

;extension=php_oci8.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll

After :

extension=php_oci8.dll
extension=php_pdo_oci.dll
extension=php_pdo_oci8.dll

Make the above correction in both php.ini files and save it .

For the Oracle part :

1. Run the Oracle server.

2. If the oracle server is running then , isqlplus command will run in Command prompt.

3. Go to Start -> Run -> cmd

4. And Type the following command (according to my PC)to run sqlplus:

Sqlplus scott/tiger@ORCL

sql

[Format : sqlplus username/password@service-name]

5. If stage 4 runs successfully then , type the following command in command Prompt (to run Listener):

lsnrctl

lsnrctl-1

>stop

lsnrctl-2

>start

lsnrctl-3

lsnrctl-4

6. If the stage 5 runs correctly then , type following command in command Prompt (to test connection)

[Format : tnsping service-name]

tnsping orcl

tnsping

If it successfully loaded , then the last line will show OK with some time that have taken to run the server .

Finally , create a file named oracle-php.php and test this code :

<?php
$conn = oci_connect('scott', 'tiger', '');
$sql  = oci_parse($conn, 'select * from emp');
oci_execute($sql);
while ($row = oci_fetch_assoc($sql))
echo $row['ENAME'] . "<br>";
?>

save it .

and put this file under wamp server in the wamp/www in a new folder.

1. To check that php is having connection with oci (Oracle Call Interface )

If you have the wamp welcome page , then click on phpinfo()

or

Write this code and save it with .php:

       <?php
           phpinfo();
       ?>

Inside this phpinfo() , search for “OCI8 Support”. If you get it “enabled” state , then it has got the connection with Oracle .

oci

Now run the oracle-php.php file and get the following output (according to my database ):

result

…………………….

Done.. PHP 5 and Oracle 10G connected …

I hope it has also connected for you.

You may face some problems…

This is the simple way I configured my PHP-Oracle in 2009.

Advertisement

8 responses to this post.

  1. Posted by Arnaud on July 15, 2010 at 3:51 pm

    Bonjour, j’aimerais avoir la procédure à suivre pour configurer oracle 10g, php5.2.13, et apache2.2 de telle sorte qu’ils puissent interagir

    Reply

  2. Posted by Anand on September 21, 2010 at 12:00 pm

    very veryyy benefitial !!!!!!!!!!!

    Reply

  3. Posted by Rajib on January 30, 2011 at 2:36 pm

    very helpful ….

    Reply

  4. Posted by ahmed baig on April 15, 2011 at 1:39 pm

    AOA zahid
    this forum helped me alot but what if im not getting OK at the end of stage 6.
    kindly help me m in greate trouble

    Reply

  5. Posted by Al Noman on May 5, 2011 at 4:44 pm

    why show these message???
    i dont rtrive any data…
    Warning: oci_execute() [function.oci-execute]: ORA-00942: table or view does not exist in E:\wamp\www\New Folder\tr.php on line 7

    Warning: oci_fetch_assoc() [function.oci-fetch-assoc]: ORA-24374: define not done before fetch or execute and fetch in E:\wamp\www\New Folder\tr.php on line 9

    i dont rtrive any data…

    Reply

  6. Posted by Saswat Arabinda on May 18, 2011 at 3:38 pm

    thanks bro. this is very very useful

    Reply

  7. Posted by agam on October 23, 2011 at 11:17 pm

    do it in another cmd window

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s