Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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.
";
                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:xamppphpextphp_oci8.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'C:xamppphpextphp_oci8.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'C:xamppphpextphp_oci8_11g.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'C:xamppphpextphp_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() 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...