1

I have a simple php script:

<?php


            $DB = '//10.11.201.170:1521/XE';
            $DB_USER = 'BIOTPL';
            $DB_PASS = 'biotpl';
            $DB_CHAR = 'AL32UTF8';

            $conn = oci_connect($DB_USER, $DB_PASS, $DB, $DB_CHAR);
            if($conn)
            {
                echo "Successfully connected to Oracle.\n";
                OCILogoff($c);
                //$statement = oci_parse($conn, 'select 1 from dual');
                //oci_execute($statement);
                //$row = oci_fetch_array($statement, OCI_ASSOC+OCI_RETURN_NULLS);
            }
            else
            {
                $err = OCIError();
                echo "Connection failed." . $err[text];
            }  
?>

When I run it (from a browser or from the command line), I get the error::

Call to undefined function oci_connect

I'm using php 5.6.24 . I have copied php_oci8.dll and php_oci8_11g.dll to /ext folder . I have

extension=php_oci8.dll 
extension=php_oci8_11g.dll  

in my php.ini I have installed instant client_11_2 - tried 32 bit version . I have ORACLE_HOME and TNS_ADMIN environment variables pointing at the instant client folder ( C:\instantclient_11_2 ).

I have spent several hours over several days trying different things to no avail.

I have Installed Microsoft Visual C++ 2010 Runtime (x86). This is needed for the OCI8 extension. I have Installed Microsoft Visual C++ 2012 Runtime (x86). This is needed for PHP.

When I have tried the following command :

php --ri oci8

I have the following error :

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_oci8.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_oci8.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_oci8_11g.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_oci8_11g.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0
Extension 'oci8' not present.

How can I remove the following error ?

Fatal error: Call to undefined function oci_connect() 
Christopher Marlowe
  • 2,098
  • 6
  • 38
  • 68

3 Answers3

5

You are getting startup errors for the OCI8 extension indicating that you are using an unsupported dll for your php version. You need to use the correct one, which - for PHP 5.6.x - is one of these:

You need to take the one that matches your architecture (x86 or x64), compiler (vc 9, 11, 14) and thread-safe (ts) or non-thread-safe (nts) php version, e.g. if you are running a thread-safe PHP 5.6.24 compiled with vc11 on an x86, you'd use

php_oci8-2.0.8-5.6-ts-vc11-x86.zip
-------- ----- --- -- ---- --- ---
^        ^     ^   ^  ^    ^   ^
|        |     |   |  |    |   \_____ extension
|        |     |   |  |    \_________ architecture
|        |     |   |  \______________ compiler
|        |     |   \_________________ thread-safety mode
|        |     \_____________________ php version
|        \___________________________ extension version
\____________________________________ extension name

If there is no download matching your PHP, then it does not exist and you need to compile it yourself. More info at http://windows.php.net

On a side note: in addition to the above, you can only use one oci extension at a time. You got both (php_oci8.dll and php_oci8_11g.dll). Make sure to remove the one you don't need.

Gordon
  • 312,688
  • 75
  • 539
  • 559
  • I have downloaded php_oci8-2.0.8-5.5-ts-vc11-x64.zip . Then after extracting the dll I have paste the dll to C:\xampp\php\ext . But still the same error . – Christopher Marlowe Nov 28 '16 at 12:05
  • 1
    The phpinfo output you showed me in chat indicated you are running a thread-safe PHP on an x86. Your question states you are using PHP 5.6. You need to use the correct extension for your php version. – Gordon Nov 28 '16 at 12:06
  • Useful general info but perhaps not the whole picture for this particular problem. – Christopher Jones Dec 06 '16 at 03:11
  • @ChristopherJones maybe not the whole picture, but the essential picture: the OP didn't use the right extension for his PHP version (evident from the startup errors). In this particular case, both extensions had the wrong version. I left it to the OP to fix the right one. Apparently this was good enough for the OP to tick the answer as accepted (he also confirmed it works in chat). Just removing the unneeded extension would not have fixed the issue. It would still have been the wrong extension version for this php version. – Gordon Dec 06 '16 at 07:04
  • @Gordon it was a comment not a criticism. I see you've copied part of my answer into your edits, but as long as users get the right info, that's the main thing. – Christopher Jones Dec 09 '16 at 01:52
1

You can only enable one of these at a time: extension=php_oci8.dll extension=php_oci8_11g.dll They both enable the same OCI8 extension but they require different Oracle Instant Client versions. You say you are using Instant Client 11.2, so comment out the first extension.

Make sure you add the Instant Client directory to PATH.

Christopher Jones
  • 9,449
  • 3
  • 24
  • 48
-2

In my case it was better to reinstall xampp