Connect PHP with Oracle database

I spent the last four days looking for the correct way to Connect Apache server (PHP) with Oracle database, unfortunatly I didn’t find any complete article.So in this blog, I’m giving my expernce to connect ’em 2geth

1. Install Apache server:

I make this step in a seprated blog page, plz check it from this link:Install Apache HTTP server

2. Extract the PHP zip folder:

1. Unzip the PHP file into c:\php

2. Copy all the files with the .dll extension to C:\WINDOS\system

3. Copy php5apache2.dll to C:\Apache\Apache2\modules

3. Copy the file php.ini-recommended and then edit it:

1. Open C:\php then copy the file php.ini-recommended to C:\WINDOWS

2. Rename it to be php.ini then open it with text editor

3. Set the doc_root to be: doc_root = c:\apache\apache2\htdocs

4. Set the extension_dir to: extension_dir = “C:\php\ext”

5. Uncomment (Remove the semicolon “;” from the beginning of the line) this line:

session.save_path = “c:/temp”

6. Uncomment the line: extension=php_oci8.dll

4.Edit the http.conf file:

1. Open the httpd file using any text editor, which exist on the path


2. Find the line AllowOverride None and change the None value to be All

3. Look for the line DirectoryIndex index.html index.html.var and replace it with this line: DirectoryIndex index.html index.html.var index.php

4. Search for a section that has a lot of AddType commands, then added this line: AddType application/x-httpd-php .php so u have a total of 3 AddType command.

5. Search for a section has many Loads and add this line to it:

LoadModule php5_module modules/php5apache2.dll

5.Restart the Apache and the oracle database:

1. Restart the apache server using the cmd command (U can do it from the services but using the cmd has the advantage of showing errors while restarting the apache if there is any)

  • Open start -> run -> cmd -> cd c:\apache\apache2\bin (press enter)
  • The write apache –k restart (Press enter)

2. Restart the Oracle database

Open control panerl -> administrative tools -> services -> the restart all the services starting with Oracle

6. Test the connection:

1. To make the basic connection you need some information from the tnsnames.ora file, so follow the link C:\oracle\product\10.2.0\db_1\NETWORK\ADMIN Then open it

2. Open textpad page or use any text editor you want the past this code:



if ($c=OCILogon(“system”, “your database password“, $db)) {

echo “Successfully connected to Oracle.\n”;


} else {

$err = OCIError();

echo “Connection failed.” . $err[text];



Where the HOST is taken from your tnsnames.ora file and SID value is equal to your database name Then save the file with the name test.php

3. Open web browser page and type on the title: http://localhost/test.php

If it all worked well you will get white page with the result:

Successfully connected to Oracle.

NOTE: Recommended links to download the software’s:




Oracle Database 10g Express Edition


Apache HTTP Server


PHP Hypertext Processor


This entry was posted in PHP and Oracle database and tagged , , , . Bookmark the permalink.

46 Responses to Connect PHP with Oracle database

  1. Sanjay says:

    Nice article. Keep up the good work. It would be great if you can share web pages, with CSS.

  2. me2blog says:

    Thanks Sanjay …
    I hope that I will add more into this topic after finishing my mid-term exams 🙂

  3. Kyle says:

    Thanks for the assistance. I ran across many forums, none with direct answers. Thanks for being straight forward and helpful, saved me alot of hairpulling/head-banging.

  4. supercalculo says:

    Hello. I did everything, like you say and no work. its like not recognize the “OCILogon”. after this line nither a echo “somthing” work.

  5. supercalculo says:

    Everything is in my local machine… I have download the versions you say and nothing…! any help?

    This is my code:
    echo "mensaje ";
    $db = "(DESCRIPTION=(ADDRESS = (PROTOCOL = TCP)(HOST = personal-8b538f)(PORT = 1521))(CONNECT_DATA=(SID=system)))" ;

    echo "mensaje 7″.$db.””;
    if ($c=OCILogon(“system”, “123456”, $db)) {
    echo “Conectado a Oracle”;
    } else {
    $err = OCIError();
    echo “Conexion Fallida.” . $err[text];
    echo “mensaje 3”;

  6. Hi, is this a wordpress blog using Oracle?

    I need a CMS, but in wordpress site it doesnt tells anything about Oracle.

    Best regards.

  7. Kazi Ataul Bari says:

    Great Tutorial

  8. Mudassir Khan says:


    I am using Xampp and I have successfully connected with MySQL. Now I wish to connect to Oracle server. I did what you have mentioned but I am getting the following error.

    Parse error: parse error in C:\mysite\documents\OracleConnect.php on line 3

    here is my code:

  9. Mudassir Khan says:
  10. TAREQ says:

    hi, thanks a lot for your perfect article and your great effort ,

    I have done all your steps but when I tried to restart the apache I got error which tell me “apache: Syntax error on line 130 of C:/xampp/apache/conf/httpd.conf: Cannot load
    C:/xampp/apache/modules/php5apache2.dll into server: The specified module could
    not be found.”

    i was using xampp so I have made little change in files path
    but i don’t why it dive me this error .

    i hope you can answer me soon

    thanks again


  11. sona says:

    hello from this web site i can configuration or connection PHP to Oracle
    and i hope than i can learn other from this site thank you!!!!!!

  12. Ivan says:

    i’m using Oracle 10.2.0 ,and i have both of tomcat and apache2triad ,and the tnsnames.ora has the following :

    XE =
    (ADDRESS = (PROTOCOL = TCP)(HOST = gleeds)(PORT = 1521))

    (SID = PLSExtProc)

    (SID = CLRExtProc)

    so how would my code will be ?

  13. Hiba says:

    Hello dear, this an amazing useful straigt forward blog wich answered alot of my questions, except one

    does it make sense if we use Oracle Enterprise Edition 10g? with PHP wamp server 2.0??? rather than Oracle XE with Appatche?

  14. Pramod Rawat says:

    I am new with php will you tell me step by step procedure to connect oracle with php

  15. Jason says:

    Thanks a lot, I am just looking at how to do a large scale application with PHP, using Mysql Cluster or Oracle.

  16. vasim says:

    Warning: oci_connect() [function.oci-connect]: ORA-12537: TNS:connection closed in C:\wamp\www\oracle.php on line 5

    Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\oracle.php on line 5

  17. vasim says:

    Warning: oci_connect() [function.oci-connect]: ORA-12541: TNS:no listener in C:\wamp\www\oracle.php on line 5

  18. GANESH says:


  19. sangeeth says:

    This was my interview question.Any which ways thanks a lot….:)

  20. sanmarady says:

    Hello sir,

    I try to test on window server 2003 of my vmware.
    window server 2003 has: php, apache, and oracle
    I tested it work well for php code connect to oracle.

    But I try to connect from my window 7 to window server 2003
    window 7 has: php, apache.

    in code connection, I work in my local host. I enabled php extension php_oci8 already.
    I got error: Fatal error: Call to undefined function oci_connect() in C:\wamp\www\PHP\oracletest\testphpoci8.php on line 3

    why in window server 2003 has oracle it works well?
    why in my local machine window 7 doesn’t work to connect oracle?

    Have you ever met this problem? Does it require any service in window 7 to connect oracle?

    I am looking forward to hear from you soon.

    Thank you.

    Best regard!

  21. sanmarady says:

    I got error like this Fatal error: Call to undefined function oci_connect() in C:\wamp\www\PHP\oracletest\testphpoci8.php on line 3

    when I try to connect from my window 7 local host to window server 2003 (vmware) – installed oracle on it.

    I enabled php_oci8 already for php.

    Any solution, let’s share.

  22. ravi says:

    Hi, can anyone say how to connect particular database in oracle10g by using php. Can we connect to oracle in by using word press?

  23. Roger Sevilla says:

    The solution to resolve the next error::::
    “Unable to load dynamic library ‘C:\…ext\php_oci8.dll’

    You need to install first oracle client 10g or client according your db… in your web server.

    Best Regards.

    Roger Sevilla

  24. sindhu priya.c says:

    recent project in php

  25. HELLO..
    I have already install wamp and I user remote server for oracle ,it is 10g

    I downloaded the instant client and unzipped it to the following directory: C:\instantclient_101_2
    – I uncommented the extension=php_oci8.dll in the php.ini file
    – I set the PATH environment variable to the following value. (I have restarted by PC several times to make sure)

    $srvr = oci_connect(‘username’,’password’,’10.xx.xx.10:1521/devo10g’);
    $qstring = “select ‘It Works’ as test from dual”;
    $q = oci_parse($srvr,$qstring);
    $data = oci_fetch_assoc($q);
    echo $data[“TEST”];

    I get this error:
    ” Warning: ocilogon() [function.ocilogon]: OCIEnvNlsCreate() failed. There is something wrong with your system – please check that PATH includes the directory with Oracle Instant Client libraries in ”

    help me to solved this.plz..

    • Nsh15 says:

      Unfortunately, didn’t work with oracle since 2009 so I’m sorry but I forget the details, I’m in the Cisco networking field .. apologize

  26. Pingback: Activate Oracle on XAMPP for Windows : OCI8 : XAMPP ORACLE CONFIGURATION | POiSON WORLD

  27. Good post. I’m dealing with a few of these issues as well..

  28. Awais says:

    Dear guys , if you have difficulty in configuration you can visit this link where step by step configuration is written

  29. says:

    I go to see day-to-day a few sites and information sites to read articles or reviews, but this webpage gives feature
    based content.

  30. Thanks for any other fantastic post. Where else may just anyone get that kind of information in such an ideal means of writing?

    I have a presentation next week, and I am at the look for such info.

  31. You might even link a Twitter account to your Facebook page and have
    all tweets show up there as well. There’s a million and one ways. Use your business logo or produce a poster that’s
    eye-catching and easily readable.

  32. tika uRmm says:

    is it impossible to connect the oracle basic version with windows 64 bit? btw, is it the tutorial can be used for 11gr2? since the link u provided lead me to 11gr2 package..

  33. Eulalia says:

    magnificent issues altogether, you just received a logo new reader.
    What might you suggest in regards to your post that
    you simply made a few days ago? Any sure?

Leave a Reply

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

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

Google photo

You are commenting using your Google 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