Tuesday, July 13, 2010

How to Connect Php 5 and oracle 10g in window xp

· Install the WampServer 2.0 or Newer Version (for running php )

· Install the Oracle 10g







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.iniC:\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 Oracle part :
1. Run the Oracle server.

2. If the oracle server is running then ,start sqlplus.

3.Enter user name "scott" and password "tiger" and enter into database or you can run by command prompt



from sqlplus:-


or From command prompt:-

1. Go to Start -> Run -> cmd

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

c:>Sqlplus scott/tiger@ORCL



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




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


c:>lsnrctl


lsnrctl>stop




lsnrctl>start


Now-Exit by Typing Exit on command prompt.

lsnrctl>exit

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

[Format : tnsping service-name]


c:>tnsping orcl


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'] . "
";

?
"
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()



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





After Running php file the o/p is like this...




…………………….

Done.. PHP 5 and Oracle 10G connected …

I hope it has also connected for you.
...all the best...

1 comment: