简体   繁体   English

调用未定义的函数oci_connect,php_oci8_12c.dll,windows 8.1,php5.6.6

[英]Call to undefined function oci_connect, php_oci8_12c.dll, windows 8.1, php5.6.6

I have a simple php script: 我有一个简单的PHP脚本:

<?php
$db_user = 'myusername';
$db_pass = 'mypassword';
$db_sid = 'mysid';
$conn = oci_connect( $db_user, $db_pass, $db_sid );
?>

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.6 which came with php_oci8_12c.dll already there. 我正在使用PHP 5.6.6,它已经附带了php_oci8_12c.dll。

I have extension=php_oci8_12c.dll in my php.ini 我的php.ini中有extension=php_oci8_12c.dll

I have installed instant client (12.1) - tried 32 bit version AND 64 bit version 我已经安装了即时客户端(12.1) - 尝试过32位版本和64位版本

I have ORACLE_HOME and TNS_ADMIN environment variables pointing at the instant client folder ( C:\\instantclient_12_1 ). 我有ORACLE_HOME和TNS_ADMIN环境变量指向即时客户端文件夹(C:\\ instantclient_12_1)。

I also have C:\\instantclient_12_1 in my path 我的路径中也有C:\\ instantclient_12_1

I have a tnsnames.ora in that same folder with this relevant entry in it: 我在同一个文件夹中有一个tnsnames.ora,其中包含相关条目:

MYSID =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = myhost.net)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = MYSERVICE)
    )
  )

I have also downloaded SQLDeveloper from http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html 我还从http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html下载了SQLDeveloper

SQLDeveloper works, recognizes the above mentioned tnsnames.ora and connects and successfully runs a query on the same database that my php script is trying to access. SQLDeveloper工作,识别上面提到的tnsnames.ora并连接并成功运行我的php脚本试图访问的同一数据库上的查询。

I have spent several hours over several days trying different things to no avail. 几天后我花了几个小时尝试不同的事情无济于事。

I'm using: 我正在使用:

php 5.6.6
windows 8.1
IIS (so no answers involving apache please)
cmd (run as administrator)
Oracle Database 11g Enterprise Edition 11.2.0.3.0 

Some other information that might prove useful: 其他一些可能有用的信息:

I would ideally like to use oci 1.4.10 to match the production server, but not too worried about that for now. 理想情况下,我希望使用oci 1.4.10来匹配生产服务器,但现在不要太担心。

pear install oci8-1.4.10.tgz

gives me this error: 给我这个错误:

The DSP oci8.dsp does not exist

I can't find any explanation on that error that means anything to me. 我找不到任何关于那个对我来说意味着什么的错误的解释。

What am I missing - can anyone help me 我错过了什么 - 任何人都可以帮助我

EDIT: 编辑:

I have tried the various suggestions in other posts on stackoverflow, namely: 我在stackoverflow上的其他帖子中尝试了各种建议,即:

extension=oci8.so with and without extension=php_oci8_12c.dll extension=oci8.so有和没有extension=php_oci8_12c.dll

I don't have the line extension=php_oracle.dll in my php.ini file 我的php.ini文件中没有行extension=php_oracle.dll

EDIT: 编辑:

phpinfo tells me that I am using the correct php.ini file: phpinfo告诉我,我正在使用正确的php.ini文件:

Loaded Configuration File => C:\php5.6.6\php.ini

This line from phpinfo might also be of use: 来自phpinfo的这一行也可能有用:

Configure Command => cscript /nologo configure.js  "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--with-oci8-12c=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--without-analyzer" "--with-pgo"

EDIT: 编辑:

It seems that dsp files are VC++ project files - I am now venturing on learning how to create a php extension, and hopefully when I've done that I'll have enough knowledge to compile the oci8 1.4.10 source code into a dll that works on windows 8 - unless somebody rescues me with the answer to this question - this looks like it is going to take me some time :-) 似乎dsp文件是VC ++项目文件 - 我现在正在学习如何创建一个php扩展,并希望当我完成它时,我将有足够的知识将oci8 1.4.10源代码编译成一个dll适用于Windows 8 - 除非有人用这个问题的答案解救我 - 这看起来好像需要一些时间:-)

EDIT: 编辑:

Adding display_startup_errors = On to php.ini tells me that the oci dll is not a valid Win32 application display_startup_errors = On添加到php.ini告诉我oci dll不是有效的Win32应用程序

Edit: Hmm. 编辑: 嗯。 Trying this on Windows 8 appears to generate the same error as you specified. 在Windows 8上尝试此操作似乎会生成与您指定的相同的错误。 I'm currently investigating... 我正在调查......

My mistake (I had enabled the wrong extension_dir line). 我的错误(我启用了错误的extension_dir行)。 It works in Win8 just as documented below. 它在Win8中工作,如下所述。


The following steps should be all you need to get OCI working with PHP (I've just verified this on a freshly installed Windows 2008 R2 Standard x64 virtual machine): 以下步骤应该是OCI使用PHP所需的全部内容(我刚刚在新安装的Windows 2008 R2 Standard x64虚拟机上验证了这一点):

  • Download and extract PHP (I used C:\\php from php-5.6.7-nts-Win32-VC11-x86.zip ). 下载并解压缩PHP(我使用了C:\\php来自php-5.6.7-nts-Win32-VC11-x86.zip )。
  • Download and extract InstantClient (I used C:\\instantclient_12_1 from instantclient-basic-nt-12.1.0.2.0.zip ). 下载并解压缩InstantClient(我使用了来自instantclient-basic-nt-12.1.0.2.0.zip C:\\instantclient_12_1 instantclient-basic-nt-12.1.0.2.0.zip )。
  • Add the above paths to the system path. 将上述路径添加到系统路径。
  • Copy c:\\php\\php.ini-production to c:\\php\\php.ini . c:\\php\\php.ini-production复制到c:\\php\\php.ini
  • in php.ini : php.ini
    • enabled line extension_dir = "ext" . 启用行extension_dir = "ext"
    • enabled line extension=php_oci8_12c.dll . 启用行extension=php_oci8_12c.dll
  • Install Microsoft Visual C++ 2010 Runtime (x86). 安装Microsoft Visual C ++ 2010运行时(x86)。 This is needed for the OCI8 extension. 这是OCI8扩展所必需的。
  • Install Microsoft Visual C++ 2012 Runtime (x86). 安装Microsoft Visual C ++ 2012运行时(x86)。 This is needed for PHP. 这是PHP所必需的。

At this point running php --ri oci8 in a command prompt shows me the following output: 此时在命令提示符下运行php --ri oci8显示以下输出:

C:\>php --ri oci8

oci8

OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 2.0.9
Revision => $Id: f5a3ee1083d1ffa6adb5143efda6eafa210b8414 $
Oracle Run-time Client Library Version => 12.1.0.2.0
Oracle Compile-time Instant Client Version => 12.1

Directive => Local Value => Master Value
oci8.max_persistent => -1 => -1
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
oci8.default_prefetch => 100 => 100
oci8.old_oci_close_semantics => Off => Off
oci8.connection_class => no value => no value
oci8.events => Off => Off

Statistics =>
Active Persistent Connections => 0
Active Connections => 0

And checking for the oci_connect function: 并检查oci_connect函数:

C:\>php -r "var_dump(function_exists('oci_connect'));"
bool(true)

In addition to what was said to fix the problem, I would like to add the php CLI side of things, as some people need to run OCI-enabled applications in CLI mode. 除了说解决问题之外,我想添加php CLI方面的东西,因为有些人需要在CLI模式下运行支持OCI的应用程序。 In my case, I had to copy an instance of oci.dll into the wamp/bin/php/php<version>/ folder for php --ri oci8 to show that oci8 was correctly loaded. 在我的情况下,我不得不将oci.dll一个实例复制到php --ri oci8wamp/bin/php/php<version>/文件夹中,以显示oci8已正确加载。 That doesn't prove that other files were not needed to correctly run a full-fledged application (see my technical footnote). 这并不能证明正确运行完整的应用程序不需要其他文件(参见我的技术脚注)。 Including the path to the instantclient 12 distribution wouldn't do it. 包括即时客户端12分发的路径不会这样做。

Technical notes: My environment being: Windows 7 + WAMP3 (php 5.6.15, apache 2.4.17), I was, after a number of experiments, able to narrow down the minimal set of three files that needed to be copied to the bin directory (Apache's for non-cli apps) from the instantclient 12 distribution, to allow instantiate an Oracle adapter within Zend Framework, perform an SQL query and read the recordset. 技术说明:我的环境是:Windows 7 + WAMP3(php 5.6.15,apache 2.4.17),经过多次实验,我能够缩小需要复制到bin的三个文件的最小集合来自instantclient 12发行版的目录(​​用于非cli应用程序的Apache),允许在Zend Framework中实例化Oracle适配器,执行SQL查询并读取记录集。

This set is: oci.dll , oraociei12.dll and orans.dll . 这个集合是: oci.dlloraociei12.dllorans.dll

In particular, copying just oci.dll wouldn't allow the application to work (unknow Exception raised) 特别是,只复制oci.dll不允许应用程序工作(unknow异常引发)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM