php 调用未定义的函数 oci_connect、php_oci8_12c.dll、windows 8.1、php5.6.6
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29257894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call to undefined function oci_connect, php_oci8_12c.dll, windows 8.1, php5.6.6
提问by Graham
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_oci8_12c.dll 附带的 php 5.6.6。
I have extension=php_oci8_12c.dll
in my php.ini
我extension=php_oci8_12c.dll
在我的 php.ini
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
extension=php_oracle.dll
我的 php.ini 文件中没有该行
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 应用程序
回答by timclutton
Edit:Hmm. Trying this on Windows 8 appears to generate the same error as you specified. I'm currently investigating...
编辑:嗯。在 Windows 8 上尝试此操作似乎会生成与您指定的相同的错误。我目前正在调查...
My mistake (I had enabled the wrong extension_dir
line). It works in Win8 just as documented below.
我的错误(我启用了错误的extension_dir
线路)。它在 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
fromphp-5.6.7-nts-Win32-VC11-x86.zip
). - Download and extract InstantClient (I used
C:\instantclient_12_1
frominstantclient-basic-nt-12.1.0.2.0.zip
). - Add the above paths to the system path.
- Copy
c:\php\php.ini-production
toc:\php\php.ini
. - in
php.ini
:- enabled line
extension_dir = "ext"
. - enabled line
extension=php_oci8_12c.dll
.
- enabled line
- Install Microsoft Visual C++ 2010 Runtime (x86). This is needed for the OCI8 extension.
- Install Microsoft Visual C++ 2012 Runtime (x86). This is needed for PHP.
- 下载并提取 PHP(我
C:\php
从 中使用php-5.6.7-nts-Win32-VC11-x86.zip
)。 - 下载并提取 InstantClient(我
C:\instantclient_12_1
从 中使用instantclient-basic-nt-12.1.0.2.0.zip
)。 - 将上述路径添加到系统路径中。
- 复制
c:\php\php.ini-production
到c:\php\php.ini
. - 在
php.ini
:- 启用线
extension_dir = "ext"
。 - 启用线
extension=php_oci8_12c.dll
。
- 启用线
- 安装 Microsoft Visual C++ 2010 运行时 (x86)。这是 OCI8 扩展所需要的。
- 安装 Microsoft Visual C++ 2012 运行时 (x86)。这是 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)
回答by Fabien Haddadi
In addition to what was said to fix the problem, I would like to add the php CLIside of things, as some people need to run OCI-enabled applications in CLI mode. 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. 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.
除了所说的修复问题之外,我想添加php CLI方面的内容,因为有些人需要在 CLI 模式下运行支持 OCI 的应用程序。就我而言,我必须将 的实例复制oci.dll
到wamp/bin/php/php<version>/
文件夹中php --ri oci8
以显示 oci8 已正确加载。这并不能证明正确运行成熟的应用程序不需要其他文件(请参阅我的技术脚注)。包括到 Instantclient 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 中的三个文件的最小集合目录(Apache 用于非 cli 应用程序),以允许在 Zend Framework 中实例化 Oracle 适配器,执行 SQL 查询并读取记录集。
This set is: oci.dll
, oraociei12.dll
and orans.dll
.
这个集合是:oci.dll
,oraociei12.dll
和orans.dll
。
In particular, copying just oci.dll
wouldn't allow the application to work (unknow Exception raised)
特别是,复制oci.dll
不允许应用程序工作(引发未知异常)