Activate Oracle on XAMPP for Windows : OCI8

If you want to connect with Oracle database using PHP script you will have to do some effort. Because with the default installation of XAMPP for Windows, we don’t get PHP Oracle connectivity enabled. This can be enabled easily when you need to connect to a Oracle Database from your PHP application/script. PHP has got the OCI8 extension, which provides Oracle connectivity to PHP application, and OCI8 uses Oracle Instant Client Package to get Oracle specific functions.

I had the need to connect to a Oracle Database from a PHP script in one of my recent projects, the following is what I did to enable Oracle connectivity in XAMPP for Windows.

1. In your XAMPP Start Page, go to phpinfo, look for string oci8. If string found it indicate that connection to oracle is available, otherwise to activate connection do the following steps:
2. Open the currently used php.ini file by looking at the phpinfo, from the XAMPP folder.
3. Find string ;extension=php_oci8.dll. Remove the semicolon (;) ahead of the string to activate the oracle extension.
4. Save the php.ini file.
5. Download the “Instant Client Package – Basic” for Windows from the OTN Instant Client page. Unzip it to c:\instantclient_11_1
6. Edit the PATH environment setting and add c:\instantclient_11_1 before any other Oracle directories. For example, on Windows XP, follow Start -> Control Panel -> System -> Advanced -> Environment Variables and edit PATH in the System variables list.
7. Set desired Oracle globalization language environment variables such as NLS_LANG. If nothing is set, a default local environment will be assumed. See An Overview on Globalizing Oracle PHP Applications for more details.
8. Unset Oracle variables such as ORACLE_HOME and ORACLE_SID, which are unnecessary with Instant Client (if they are set previously).
9. Restart XAMPP (or Start if its not already started).
10. To make sure that connection to oracle database has successfully activated, go to phpinfo. Find string: oci8. If found, then XAMPP can now communicate with Oracle Database.

The steps to do the same on Linux are almost similar, except there you will use the Linux versions of the packages and setting PATH variables would be different.

To test the connection you can use this script

$conn = oci_connect('username', 'password', 'host:port/servicename');
$query = 'select table_name from user_tables';
$stid = oci_parse($conn, $query);
oci_execute($stid, OCI_DEFAULT);
while ($row = oci_fetch_array($stid, OCI_ASSOC)) {
foreach ($row as $item) {
echo $item." | ";
echo "



15 thoughts on “Activate Oracle on XAMPP for Windows : OCI8

    • Did you check the dll file exists in you extension directory.

      To check, first search extension_dir in php.ini file it will be something like

      extension_dir = C:\xampp\php\ext (if you are working with xampp)

      Now search for the dll file in C:\xampp\php\ext\php_oci8.dll

  1. Good evening, my English is not good, but I’ll try to detail my problem:
    Like Nano, “if i try to do this on windows 7 ultimate, an error inform me that the php_oci8.dll WAS: unable to be loaded … what can i do?” and done what you recommended, and still does not work.

    When you start to run a connection test page, I get the following error:
    Fatal error: Call to undefined function oci_connect () in C: \ wamp \ www \ testoracle.php on line 2

    The code page is the following:

    In addition, I have installed oracle 10g express

    In advance, thanks for your prompt response.

    Best regards,

      • I have been facing the same error for 4 days, tried everything but the error is still available

        Fatal error: Call to undefined function oci_connect() in C:\xampp\htdocs\Tools\cOracle.php on line 33

        Installed XAMPP like 10 times now.

        So, I am using windows 7 with XAMPP 1.8. Steps I tried

        1. Uncomment the following line:
        extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client

        2. Checked php_oci8_11g.dll is present in php/ext folder

        3. Restarted the server (In some other xampp version, apache doesn’t ever start after uncommenting the oci8 line. But this one works fine)

        4. I have Instant Oracle client download, also checked the path and added C:\instantclient_11_1

        Please help me I need this work done. I have projects which I need to finish very soon.

  2. i have an oracle server in windows and php code in linux server then how to connect OCI8 help me as soon as possible..

  3. The instantclient version must be compatible with your XAMPP stack and ORACLE server. In my case, downloading the instantclient_10_2 (32 bits) worked for my 32bit XAMPP install and ORACLE 10g server. Also double check that your system PATH environment variable includes the correct path to your downloaded version of instantclient.

  4. oci_connect() does exists, in my phpinfo() I am locate oci string, i have xampp server , and i am allready instal oracle client , and set path bt i still have a problem

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s