Tuesday 11 December 2018

How to connect oracle with php

Downloading Dependencies

  • Download Oracle 11g here. (CLICK THE IMAGE IF ITS TOO BLUR FOR YOU)

  • Download XAMPP 1.7.4 here.

  • Download Oracle Instant Client here.


  • Download Oracle OCI 8 for the module here.
    • Choose the 7.2 Thread Safe x86

Steps:

  1. Install the Oracle, follow the instruction on how to install those downloaded 2 ZIP files.
  2. Make sure you remember the password you key-in during installation.
  3. Install XAMPP as usual.
  4. Extract the Oracle OCI 8 and copy file name 'php_oci8_11g.dll' to [C:\xampp\php\ext], override any existing files in that folder.
  5. Edit php.ini at [C:\xampp\php\php.ini], add more line for extension.
  6. Extract Oracle Instant Oracle; first make folder name Oracle at C: drive, then point the environment variable to the folder oracle [C:\oracle\instantclient_12_2].

  7. Restart XAMPP.
  8. Create connect.php file with content below,
    <?php
    $conn = oci_connect("username", "password", "//localhost/orcl");
    // Create connection to Oracle
    if (!$conn) {
       $m = oci_error();
       echo $m['message'], "\n";
       exit;
    }
    else {
       print "Connected to Oracle!";
    }
    // Close the Oracle connection
    oci_close($conn);
    ?>
    
    .
  9. Successfully connected
    .
  10. You can also check in the info.php for the OCI module has been loaded
    <?php
    
    phpinfo();
    
    phpinfo(INFO_MODULES);
    
    ?>
    
     
    .

Share:

0 comments:

Post a Comment