微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP8 + Oracle OCI8 => 致命错误:未捕获错误:调用未定义的函数 oci_connect()

如何解决PHP8 + Oracle OCI8 => 致命错误:未捕获错误:调用未定义的函数 oci_connect()

我必须升级使用 PHP 5.3 32 位、Apache2.2 32 位、Oracle 客户端 11.2 32 位运行在 Windows 64 位(Win10 用于开发,服务器用于生产)的旧应用程序。

新堆栈是 Apache2.4 32 位、PHP8 32 位和完全相同的 Oracle 客户端 11.2 32 位。

当我运行 webapp 时,我在第一次数据库连接尝试时遇到了这个错误

Fatal error: Uncaught Error: Call to undefined function oci_connect() in c:\some\path\connexion_check.PHP:16 Stack trace: #0 {main} thrown in c:\some\path\connexion_check.PHP on line 16

我的安装是使用这些软件包完成的:

  • httpd-2.4.48-win32-VS16.zip
  • PHP-8.0.8-Win32-vs16-x86.zip
  • PHP_oci8-3.0.1-8.0-ts-vs16-x86.zip
  • PHP-debug-pack-8.0.8-Win32-vs16-x86.zip

在我的 PHP.ini 文件中,我已经设置了

extension_dir = "ext"
extension=oci8_11g 

那里,我使用与 PHP5.3 相同的参数 => extension=oci8_11g 但 DLL 已更新为包 PHP_oci8-3.0.1-8.0-ts-vs16-x86.zip

运行命令 PHP --ri oci8

oci8

OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 3.0.1
Oracle Run-time Client Library Version => 11.2.0.3.0
Oracle Compile-time Instant Client Version => 11.2

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

一些 PHPINFO(来自 CLI)

PHPinfo()
PHP Version => 8.0.8

System => Windows NT D20899 10.0 build 19042 (Windows 10) i586
Build Date => Jun 29 2021 15:54:30
Build System => Microsoft Windows Server 2019 Datacenter [10.0.17763]
Compiler => Visual C++ 2019
Architecture => x86
Configure Command => cscript /nologo /e:jscript configure.js  "--enable-snapshot-build" "--enable-debug-pack" "--with-pdo-oci=..\..\..\..\instantclient\sdk,shared" "--with-oci8-19=..\..\..\..\instantclient\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--without-analyzer" "--with-pgo"
Server API => Command Line Interface
Virtual Directory Support => enabled
Configuration File (PHP.ini) Path =>
Loaded Configuration File => C:\www\PHP8\PHP.ini
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
PHP API => 20200930
PHP Extension => 20200930
Zend Extension => 420200930
Zend Extension Build => API420200930,TS,VS16
PHP Extension Build => API20200930,VS16
Debug Build => no
Thread Safety => enabled
Thread API => Windows Threads
Zend Signal Handling => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => disabled
IPv6 Support => enabled
DTrace Support => disabled

Registered PHP Streams => PHP,file,glob,data,http,ftp,zip,compress.zlib,compress.bzip2,https,ftps,phar
Registered Stream Socket Transports => tcp,udp,ssl,tls,tlsv1.0,tlsv1.1,tlsv1.2,tlsv1.3
Registered Stream Filters => convert.iconv.*,string.rot13,string.toupper,string.tolower,convert.*,consumed,dechunk,zlib.*,bzip2.*

This program makes use of the Zend Scripting Language Engine:
Zend Engine v4.0.8,copyright (c) Zend Technologies
    with Xdebug v3.0.4,copyright (c) 2002-2021,by Derick Rethans

除了这个 web 应用程序之外,我还使用相同的 InstantClient 安装管理/使用连接到我的 Oracle 数据库的其他应用程序/工具。使用 :

可以从这台计算机建立数据库连接
  • Oracle 工具
  • Powerbuilder 32 位
  • Python 32 位 + cx_Oracle
  • Microsoft Word 通过 Oracle Data Provider for .NET 和 OLEDB

我检查了很多东西,但无法弄清楚出了什么问题。 感谢您的帮助:-)

编辑:

C:\www\PHP8>PHP -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
filter
hash
iconv
json
libxml
MysqLnd
oci8
openssl
pcre
PDO
Phar
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xdebug
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]
Xdebug

解决方法

见鬼,我明白了。 这是对下一个遇到同样问题的人的解释......

这是关于我的设置的一些数据:

  • C:\WWW\
  • C:\WWW\Apache24
  • C:\WWW\PHP8
  • C:\WWW\PHP8\php.exe
  • C:\WWW\PHP8\php.ini
  • C:\WWW\PHP8\ext
  • C:\WWW\PHP8\ext\oci8_11g.dll
  • C:\WWW\MyWebApp\index.php

oci8 扩展名不是从 phpinfo() 出来的,这似乎很奇怪。 使用 Process Monitor 我发现 oci8_11g.dll 被到处搜索(根据 PATH 环境变量),但不是在正确的位置。

我在 PHP.INI 中的设置是这样的:

extension_dir = ".\ext"

和 ProcMon 显示 C:\WWW\PHP8\ext 没有被搜索到,而是 C:\WWW\Apache24\ext。

因此我了解到文件夹 .\ext 与从 C:\WWW\Apache24\bin 运行的 Apache httpd.exe 进程相关

因此,在我的 PHP.ini 文件中,我将值更改为绝对路径,以便它在 CLI 环境以及从 Apache 启动的 PHP 中兼容。

extension_dir = "c:\www\php8\ext"

重启Apache服务后,一切正常。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?