Connecting WAMP Server to Oracle With PHP's php_oci8_11g.dll

Posted: 2014-09-22 19:05:57

Download the proper Oracle Instant Client

If using 32 bit PHP, you’ll need use the 32 bit Windows Oracle Instant Client:
Instant Client Downloads for Microsoft Windows (32-bit)

Download package:
"Instant Client Package - Basic Lite"

Use version 11 of the client, not 12, with PHP’s php_oci8_11g.dll.

Unzip the package into a location such as:
C:\WampDeveloper\Tools\Oracle\

Then modify the System’s PATH Environmental Variable with the end location. As otherwise the Client’s DLL files (i.e., OCI.dll) will not be found (nor loaded) by PHP’s php_oci8_11g.dll extension…
C:\WampDeveloper\Tools\Oracle\instantclient[version]

Restart the system for PATH changes to fully propagate.

Install the VC++ 2012 Runtime

Under PHP 5.5, which is a VC11 (VS.NET 2012) build, some of the extensions depend on the full set of Microsoft VC++ 2012 Runtime DLLs.

Download and install the 32 bit VC++ 2012 Runtime Redistributable (vcredist_x86.exe):
Visual C++ Redistributable for Visual Studio 2012 Update 4

PHP 5.5 extension php_oci8_11g.dll, and other extensions such as php_intl.dll, depend on files: msvcr110.dll and msvcp110.dll, which this will place into your C:\Windows\System32 folder.

Check Dependencies of php_oci8_11g.dll

Open the command line, change to the PHP’s directory, and check to see if all php_oci8_11g.dll dependencies (DLL files) are being found.

C:
cd \WampDeveloper\Components\Php
deplister ext\php_oci8.dll
deplister ext\php_oci8_11g.dll

Everything should be listed as found, and you should not see this: OCI.dll,NOTFOUND… Which indicates that the Oracle Client DLL is not being found.

Load php_oci8_11g.dll

Edit php.ini and un-comment:

extension=php_oci8.dll
extension=php_oci8_11g.dll

Save file. Restart Apache.

Then check to make sure this module has been loaded:
http://serverhost/phpinfo.php

* phpinfo.php contains this code: <?php echo phpinfo(); ?>, and will show you all the loaded PHP extensions and their settings.

Issues

PHP Startup: Unable to load dynamic library ‘C:/WampDeveloper/Components/Php/ext\php_oci8_11g.dll’ – %1 is not a valid Win32 application.

This indicates a build-type mismatch.

The used PHP extension (php_oci8_11g.dll) is not matching the PHP build type: 32bits (x86), VC11 (VS.NET 2012), TS (Thread Safe). * TS (Thread Safe) is for Regular PHP; NTS (Not Thread Safe) is for PHP-FCGI.

Chances are you are using the 64-bit build of php_oci8_11g.dll, or a VC9 build, or a NTS build – that replaced the default ext\php_oci8_11g.dll file that PHP came with.

Unable to load dynamic library ‘C:/WampDeveloper/Components/Php/ext\php_oci8_11g.dll’ – The specified module could not be found.

The module is being found (and you can verify that it’s present), but the real problem is that it has dependencies on other DLLs which are not being found.

Update the System’s PATH Environmental Variable with the Oracle Instant Client’s OCI.dll file location.

Also make sure PHP’s root folder is in the PATH. * It and PHP’s “\ext” path should already be listed in WampDeveloper’s %wampdev% environmental variable (which itself is expanded in %path%).

* In the error message, the backslash (“\”) being used instead of the “/”, is never the problem.

Oracle Instant Client Version 11 vs. 12

You should use the Oracle Instant Client version that matches the php_oci8 extension version:

Use client version 11 for extension php_oci8_11g.dll

Use client version 12 for extension php_oci8_12c.dll

You can download the oci8 extension for client version 12 from:
http://windows.php.net/downloads/pecl/releases/oci8/

The nomenclature of the extension’s file name to built-type is:

For WampDeveloper’s PHP 5.5 (regular, not FCGI) 32bit channel, you would get this file:
php_oci8-2.0.8-5.5-ts-vc11-x86.zip

Unzip the contents into PHP “\ext” folder (make sure to overwrite all files), and load it via php.ini:

extension=php_oci8.dll
extension=php_oci8_12c.dll

PDO

If your code uses PDO methods to connect to databases, you’ll also need to load this extension:

extension=php_pdo_oci.dll

Notes

OCI8 Requirements (php.net)

Using PHP OCI8 with 32-bit PHP on Windows 64-bit

Installing PHP and the Oracle Instant Client for Linux and Windows, For PHP 5.4 and Oracle Database 11g Release 2

Installing PHP and the Oracle Instant Client for Linux and Windows, For PHP 5.5, OCI8 2.0 and Oracle Database 12c Release 1