Call to undefined function oci_connect, php_oci8_11g.dll , windows 10, php5.6.24

血红的双手。 提交于 2019-12-29 09:29:13

问题


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() 

回答1:


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:

  • http://windows.php.net/downloads/pecl/releases/oci8/2.0.8/

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.




回答2:


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.



来源:https://stackoverflow.com/questions/40843326/call-to-undefined-function-oci-connect-php-oci8-11g-dll-windows-10-php5-6-24

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!