php 调用未定义的函数 oci_connect()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22478387/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:57:38  来源:igfitidea点击:

Call to undefined function oci_connect()

phporacle

提问by user3153806

I got this error.

我收到了这个错误。

Fatal error: Call to undefined function oci_connect()
$conn = oci_connect('localhost', 'username', 'password') or die(could not connect:'.oci_error)

that is the code.

这就是代码。

This is the error I got.

这是我得到的错误。

Fatal error: Call to undefined function oci_connect() in C:\xampp\htdocs\org\org\php\myphp.php on line 51

I checked the PHP DLL files in ext folder.

我检查了 ext 文件夹中的 PHP DLL 文件。

Somebody help on this issue thanks in advance.

有人在此问题上提供帮助,提前致谢。

回答by Soichiro Cub

I just spend THREE WHOLE DAYS fighting against this issue.

我只花了整整三天的时间与这个问题作斗争。

I was using my ORACLE connection in Windows 7, and no problem. Last week I Just get a new computer with Windows 8. Install XAMPP 1.8.2. Every app PHP/MySQL on this server works fine. The problem came when I try to connect my php apps to Oracle DB.

我在 Windows 7 中使用我的 ORACLE 连接,没有问题。上周我刚买了一台装有 Windows 8 的新电脑。安装 XAMPP 1.8.2。此服务器上的每个应用程序 PHP/MySQL 都运行良好。当我尝试将我的 php 应用程序连接到 Oracle DB 时出现了问题。

Call to undefined function oci_pconnect()

调用未定义的函数 oci_pconnect()

And when I start/stop Apache with changes, a strange "Warning" on "PHP Startup" that goes to LOG with "PHP Warning: PHP Startup: in Unknown on line 0"

当我通过更改启动/停止 Apache 时,“PHP 启动”上的一个奇怪的“警告”会以“PHP 警告:PHP 启动:在第 0 行中未知”进入 LOG

I did everything (uncommented php_oci8.dll and php_oci8_11g.dll, copy oci.dll to /ext directory, near /Apache and NOTHING it works. Download every version of Instant Client and NOTHING.

我做了一切(未注释的 php_oci8.dll 和 php_oci8_11g.dll,将 oci.dll 复制到 /ext 目录,靠近 /Apache 并且没有任何效果。下载 Instant Client 的每个版本,什么也没有。

God came into my help. When I download ORACLE Instant Client 32 bits, everything works fine. phpinfo() displays oci8 info, and my app works fine.

上帝帮助了我。当我下载 ORACLE Instant Client 32 位时,一切正常。phpinfo() 显示 oci8 信息,我的应用程序运行良好。

So, NEVER MIND THAT YOUR WINDOWS VERSION BE x64. The link are between XAMPP and ORACLE Instant Client.

因此,请不要介意您的 WINDOWS 版本是 x64。该链接位于 XAMPP 和 ORACLE Instant Client 之间。

回答by Elijah Keya

Simple steps

简单的步骤

You need to enable the below extension in your php.ini

您需要在 php.ini 中启用以下扩展名

;extension=php_oci8.dll
;extension=php_oci8_11.g.dll

by removing the ";" so that the results will below:

通过删除“;” 以便结果如下:

extension=php_oci8.dll
extension=php_oci8_11.g.dll

Download Oracle Instant Client:- Preferably 32 bit. 32 bit will also work on 64 bit. You can just google: download oracle instant client windows 32 bit. Use version 11 of the client because extension=php_oci8_11.g.dllwon't work with 12. Unzip the package into a location such as C:\Oracle\instantclient_11_2.

下载 Oracle Instant Client:- 最好是 32 位。32 位也适用于 64 位。你可以谷歌:下载 oracle 即时客户端 windows 32 位。使用客户端的版本 11,因为extension=php_oci8_11.g.dll不适用于 12。将包解压缩到一个位置,例如C:\Oracle\instantclient_11_2.

Finally modify the System's PATHEnvironment Variable with end location, under system variables not user variables

最后PATH用结束位置修改系统的环境变量,在系统变量而不是用户变量下

Then you need to restart the System for PATHchanges to fully propagate.

然后您需要重新启动系统以使PATH更改完全传播。

If you just restart XAMPP/WAMP without restarting the machine the Client's DLL files (i.e. OCL.dll) will not be loaded (nor found) by PHP's php_oci8_11g.dllextension.

如果您只是重新启动 XAMPP/WAMP 而没有重新启动机器,PHP 的php_oci8_11g.dll扩展将不会加载(也找不到)客户端的 DLL 文件(即 OCL.dll)。

回答by Ron

Things to Make sure

需要确保的事情

  1. Whenever you connecting Oracle Database , try to use 32 Bit oracle client libraries, Since XAMP PHP is compiled with 32 Bit(Though you have 64 Bit windows Machine)
  2. Download Oracle Client from Download From here

  3. Paste it in C:\instantclient_12_1

  4. Then Set the path to above in System Environment Variable
  5. Then Go to C:\xampp\php\php.ini and uncomment extension=php_oci8_12c.dll
  6. Then Restart the XAMP and it should work without any Issue.
  1. 每当您连接 Oracle 数据库时,请尝试使用 32 位 oracle 客户端库,因为 XAMP PHP 是用 32 位编译的(尽管您有 64 位 Windows 机器)
  2. 从此处下载 Oracle 客户端

  3. 将其粘贴到 C:\instantclient_12_1

  4. 然后在系统环境变量中设置路径到上面
  5. 然后转到 C:\xampp\php\php.ini 并取消注释extension=php_oci8_12c.dll
  6. 然后重新启动 XAMP,它应该可以正常工作而不会出现任何问题。

回答by John Conde

You need to enable that extension in your php.ini file. See Oracle Installation:

您需要在 php.ini 文件中启用该扩展。请参阅Oracle 安装

extension=oci8.so

回答by ADT

I installed WAMPServer 2.5 (32-bit) and also encountered an oci_connect error. I also had Oracle 11g client (32-bit) installed. The common fix I read in other posts was to alter the php.ini file in your C:\wamp\bin\php\php5.5.12 directory, however this never worked for me. Maybe I misunderstood, but I found that if you alter the php.ini file in the C:\wamp\bin\apache\apache2.4.9 directory instead, you will get the results you want. The only thing I altered in the apache php.ini file was remove the semicolon to extension=php_oci8_11g.dllin order to enable it. I then restarted all the services and it now works! I hope this works for you.

我安装了 WAMPServer 2.5(32 位),也遇到了 oci_connect 错误。我还安装了 Oracle 11g 客户端(32 位)。我在其他帖子中读到的常见修复是更改 C:\wamp\bin\php\php5.5.12 目录中的 php.ini 文件,但是这对我来说从来没有用。可能是我理解错了,但是我发现如果你修改C:\wamp\bin\apache\apache2.4.9目录下的php.ini文件,你会得到你想要的结果。我在 apache php.ini 文件中唯一改变的是删除分号extension=php_oci8_11g.dll以启用它。然后我重新启动了所有服务,它现在可以工作了!我希望这对你有用。

回答by hype

Alright, folks.

好吧,伙计们。

First, use

首先,使用

<?php 
phpinfo();
?> 

and determine your PHP Version (located at the very top, e.g. 7.0.xxx) and also, your PHP Version architecture: x64 or x86 and also, Thread Safe or Not THread Safe (located in the first table as "Thread Safety".) "Disabled" obviously means "Not Thread Safe".

并确定您的 PHP 版本(位于最顶部,例如 7.0.xxx)以及您的 PHP 版本架构:x64 或 x86 以及线程安全或非线程安全(位于第一个表中的“线程安全”。) “禁用”显然意味着“不是线程安全的”。

It is absolutely critical that the following three pieces of software that you will need are:

您需要的以下三个软件绝对至关重要:

  1. for the same major version of PHP (7.0 for 7.0.xxx)
  2. same version of Oracle as the version you are accessing (11g, 12g, etc)
  3. the same Not Thread Safe / Thread Safe version of PHP
  4. all for the same architecture.
  1. 对于相同的 PHP 主要版本(7.0.xxx 为 7.0)
  2. 与您访问的版本相同的 Oracle 版本(11g、12g 等)
  3. 相同的非线程安全/线程安全版本的 PHP
  4. 都是为了同一个架构。

If any of the following are for a different architecture, Not Thread Safe/Thread Safe version, PHP major version number, or database version, you'll get errors:

如果以下任何一项适用于不同的体系结构、非线程安全/线程安全版本、PHP 主要版本号或数据库版本,您将收到错误消息:

 1. PHP for Windows
 2. OCI8 PECL Drivers for PHP (https://pecl.php.net/package/oci8)
 3. Oracle Instant Client

Remember: If you are connecting to an 11g Oracle instance, you need an 11g driver.

请记住:如果您要连接到 11g Oracle 实例,则需要一个 11g 驱动程序。

Second, install the correct PHP, OCI8 PECL Driver, and instant client.

其次,安装正确的 PHP、OCI8 PECL 驱动程序和即时客户端。

I chose:

我选择了:

d:\php\ for php
d:\oci\ for instant client
unzip the contents of the OCI8 PECL Driver into d:\php\ext\

Third, modify d:\php\php.ini according the instructions given by Oracle:

、按照Oracle给出的说明修改d:\php\php.ini:

1. set the extension directory
2. set only one of the following:
  a. for 11g drivers, use extension=php_oci8_11g.dll
  b. for 12c drivers, use extension=php_oci8_12c.dll
  c. for other oracle DB drivers, use the correct oracle extension.

Fourth: Add d:\oci\ (or whatever your instant client install location is) to your system PATH.

第四:将 d:\oci\(或任何您的即时客户端安装位置)添加到您的系统路径。

Fifth: reboot your PC.

第五:重启你的电脑。

Sixth, on a command prompt, type "where oci*" and verify that your Instant Client install path version of oci.dll is present.

第六,在命令提示符下,键入“where oci*”并验证您的 Instant Client 安装路径版本的 oci.dll 是否存在。

Seventh, go to d:\php\ and type "php -m" and you should see OCI8 in the list.

第七,转到 d:\php\ 并键入“php -m”,您应该会在列表中看到 OCI8。

If you do not see OCI8 in the list of modules after typing "php -m", open up d:\php\errorlog.txt

如果输入“php -m”后在模块列表中没有看到OCI8,请打开d:\php\errorlog.txt

If you see something like:

如果你看到类似的东西:

PHP Warning:  PHP Startup: Unable to load dynamic library 'ext\php_oci8_11g.dll' - %1 is not a valid Win32 application.

then either instant client or your PECL driver download is not the same architecture as your PHP version.

那么即时客户端或您下载的 PECL 驱动程序与您的 PHP 版本的架构不同。

If you see something like:

如果你看到类似的东西:

PHP Warning:  PHP Startup: Unable to load dynamic library 'ext\php_oci8_12c.dll' - The specified procedure could not be found.

then you are using the wrong OCI8 PECL driver for your version of instant client.

那么您为您的即时客户端版本使用了错误的 OCI8 PECL 驱动程序。

Hope this helps.

希望这可以帮助。

回答by David Willis

I installed Wamp & expected everything to work out of the box. Not so. I have 2 Oracle clients on my x64 Windows machine (instant and full). If anyone else has a similar setup, the trick is to make sure the instant client is (a) in your Path environment variable and (b) precedes the full client in the Path variable. There's a really brief section on Windows herebut it gave the answer.

我安装了 Wamp 并希望一切都能开箱即用。不是这样。我的 x64 Windows 机器上有 2 个 Oracle 客户端(即时和完整)。如果其他人有类似的设置,诀窍是确保即时客户端 (a) 在您的 Path 环境变量中,并且 (b) 在 Path 变量中的完整客户端之前。有Windows上的真正简短的章节在这里,但它给出了答案。

回答by Abdul Kayum Khan

  1. Check your php –version as like as PHP 5.6.32 (cli) (built: Oct 25 2017 16:02:15).
  2. Using the OCI8 extension to access Oracle Database. So Download php_oci8.dll from 1https://pecl.php.net/package/oci8/2.0.8/windows. (5.6 Thread Safe (TS) x86 ) php_oci8.dll must be the same version with your php version.Then unzipped it and you will find 1.php_oci8.dll 2.php_oci8_11g.dll (as per your oralce version) these two file pasted into your
    (xampp\php\ext) folder.

  3. Open your php.ini file and add these extension=php_oci8.dll extension=php_oci8_11g.dll

  4. Check your oracle version and service name using these commands

    1. Open your cmd
    2. sqlplus / as sysdba
    3. select * from v$version; Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production, our oracle version is 11g so we can use instantclient_11_1 (Instant Client 32-bit) downloads from https://www.oracle.com/technetwork/topics/winsoft-085727.html
  5. show parameter service_name; service_name is orcl (you should remember this service name)

  6. After downloading instantclient_11_1 unzipped it and then pasted in your Local Disk. And copy the path C:\instantclient_11_1 and then set this path as your user variable & system variable. Note is that my code is working without setting path variable.

  7. Open your cmd and enter into SQL, create your schema following these commands

    1. sqlplus / as sysdba
    2. create user dbname identified by pass123;
    3. grant connect,resource to dbname;

    4. Create table user_info and insert data into your table and commit out. Note: you must commit your data either data is not inserted.

    5. Then this script run in your htdocs
  1. 检查您的 php –version 就像 PHP 5.6.32 (cli)(构建时间:2017 年 10 月 25 日 16:02:15)。
  2. 使用 OCI8 扩展访问 Oracle 数据库。所以从1 https://pecl.php.net/package/oci8/2.0.8/windows下载 php_oci8.dll 。(5.6 Thread Safe (TS) x86 ) php_oci8.dll 必须和你的 php 版本相同。然后解压,你会发现 1.php_oci8.dll 2.php_oci8_11g.dll (根据你的oralce 版本) 这两个文件粘贴进入您的
    (xampp\php\ext) 文件夹。

  3. 打开你的 php.ini 文件并添加这些 extension=php_oci8.dll extension=php_oci8_11g.dll

  4. 使用这些命令检查您的 oracle 版本和服务名称

    1. 打开你的cmd
    2. sqlplus / 作为 sysdba
    3. 从 v$version 中选择 *;Oracle 数据库 11g 企业版 11.2.0.1.0 版 - 生产,我们的 oracle 版本是 11g,因此我们可以使用从https://www.oracle.com/technetwork/topics/winsoft-085727下载的 instantclient_11_1(即时客户端 32 位).html
  5. 显示参数 service_name; service_name 是 orcl(你应该记住这个服务名称)

  6. 下载后 Instantclient_11_1 解压缩它,然后粘贴到您的本地磁盘中。并复制路径 C:\instantclient_11_1 然后将此路径设置为您的用户变量和系统变量。请注意,我的代码在没有设置路径变量的情况下工作。

  7. 打开你的 cmd 并输入 SQL,按照这些命令创建你的架构

    1. sqlplus / 作为 sysdba
    2. 创建由 pass123 标识的用户 dbname;
    3. 授予连接,资源到 dbname;

    4. 创建表 user_info 并将数据插入表中并提交。注意:您必须提交数据,否则不会插入数据。

    5. 然后这个脚本在你的 htdocs 中运行

<html>
<head><title>Oracle demo</title></head>
<body>
<?php

// Create connection to Oracle
$conn = oci_connect("dbname", "pass123", "//localhost/orcl");  // orcl is your service_name

$query = 'select * from user_info';
$stid = oci_parse($conn, $query);
$r = oci_execute($stid);

// Fetch each row in an associative array
print '<table border="1">';
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC)) {
   print '<tr>';
   foreach ($row as $item) {
       print '<td>'.($item !== null ? htmlentities($item, ENT_QUOTES) : '&nbsp').'</td>';
   }
   print '</tr>';
}
print '</table>';

回答by mustafa-naeem

try this

尝试这个

in the php.ini file uncomment this

在 php.ini 文件中取消注释这个

extension_dir = "./""remove semicolon"

extension_dir = "./"“删除分号”

回答by Frank

I had the same issue, the solution on this pagehelped me, it's caused by using incompatible oci ddl files.

我遇到了同样的问题,此页面上的解决方案对我有帮助,这是由使用不兼容的 oci ddl 文件引起的。

Hope it helps.

希望能帮助到你。