[英]Call to undefined function oci_connect()
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 文件。
I just spend THREE WHOLE DAYS fighting against this issue.我只花了整整三天的时间与这个问题作斗争。
I was using my ORACLE connection in Windows 7, and no problem.我在 Windows 7 中使用我的 ORACLE 连接,没有问题。 Last week I Just get a new computer with Windows 8. Install XAMPP 1.8.2.
上周我刚买了一台装有 Windows 8 的新电脑。安装 XAMPP 1.8.2。 Every app PHP/MySQL on this server works fine.
此服务器上的每个应用程序 PHP/MySQL 都运行良好。 The problem came when I try to connect my php apps to Oracle DB.
当我尝试将我的 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 行中未知”进入日志
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.
当我下载 ORACLE Instant Client 32 位时,一切正常。 phpinfo() displays oci8 info, and my app works fine.
phpinfo() 显示 oci8 信息,我的应用程序运行良好。
So, NEVER MIND THAT YOUR WINDOWS VERSION BE x64.因此,请不要介意您的 WINDOWS 版本是 x64。 The link are between XAMPP and ORACLE Instant Client.
该链接位于 XAMPP 和 ORACLE Instant Client 之间。
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.下载 Oracle Instant Client:- 最好是 32 位。 32 bit will also work on 64 bit.
32 位也适用于 64 位。 You can just google: download oracle instant client windows 32 bit.
你可以谷歌:下载 oracle 即时客户端 windows 32 位。 Use version 11 of the client because
extension=php_oci8_11.g.dll
won't work with 12. Unzip the package into a location such as C:\\Oracle\\instantclient_11_2
.使用客户端的版本 11,因为
extension=php_oci8_11.g.dll
不适用于 12。将包解压缩到一个位置,例如C:\\Oracle\\instantclient_11_2
。
Finally modify the System's PATH
Environment Variable with end location, under system variables not user variables最后用结束位置修改系统的
PATH
环境变量,在系统变量而不是用户变量下
Then you need to restart the System for PATH
changes to fully propagate.然后您需要重新启动系统以使
PATH
更改完全传播。
If you just restart XAMPP/WAMP without restarting the machine the Client's DLL files (ie OCL.dll) will not be loaded (nor found) by PHP's php_oci8_11g.dll
extension.如果您只是在没有重新启动机器的情况下重新启动 XAMPP/WAMP,PHP 的
php_oci8_11g.dll
扩展将不会加载(也找不到)客户端的 DLL 文件(即 OCL.dll)。
Things to Make sure需要确保的事情
Download Oracle Client from Download From here从此处下载 Oracle 客户端
Paste it in C:\\instantclient_12_1将其粘贴到 C:\\instantclient_12_1
You need to enable that extension in your php.ini file.您需要在 php.ini 文件中启用该扩展。 See Oracle Installation :
请参阅Oracle 安装:
extension=oci8.so
I installed WAMPServer 2.5 (32-bit) and also encountered an oci_connect error.我安装了 WAMPServer 2.5(32 位),也遇到了 oci_connect 错误。 I also had Oracle 11g client (32-bit) installed.
我还安装了 Oracle 11g 客户端(32 位)。 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.
我在其他帖子中读到的常见修复是更改 C:\\wamp\\bin\\php\\php5.5.12 目录中的 php.ini 文件,但这对我来说从来没有用。 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.
可能是我理解错了,但是我发现如果你修改C:\\wamp\\bin\\apache\\apache2.4.9目录下的php.ini文件,你会得到你想要的结果。 The only thing I altered in the apache php.ini file was remove the semicolon to
extension=php_oci8_11g.dll
in order to enable it.我在 apache php.ini 文件中唯一更改的是删除
extension=php_oci8_11g.dll
的分号以启用它。 I then restarted all the services and it now works!然后我重新启动了所有服务,它现在可以工作了! I hope this works for you.
我希望这对你有用。
Using the OCI8 extension to access Oracle Database.使用 OCI8 扩展访问 Oracle 数据库。 So Download php_oci8.dll from 1 https://pecl.php.net/package/oci8/2.0.8/windows .
所以从1 https://pecl.php.net/package/oci8/2.0.8/windows下载 php_oci8.dll 。 (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
(5.6 Thread Safe (TS) x86 ) php_oci8.dll 必须和你的 php 版本相同。然后解压,你会发现 1.php_oci8.dll 2.php_oci8_11g.dll (根据你的oralce 版本) 这两个文件粘贴进入你的
(xampp\\php\\ext) folder. (xampp\\php\\ext) 文件夹。
Open your php.ini file and add these extension=php_oci8.dll extension=php_oci8_11g.dll打开你的 php.ini 文件并添加这些 extension=php_oci8.dll extension=php_oci8_11g.dll
Check your oracle version and service name using these commands使用这些命令检查您的 oracle 版本和服务名称
show parameter service_name;显示参数 service_name; service_name is orcl (you should remember this service name)
service_name 是 orcl(你应该记住这个服务名称)
After downloading instantclient_11_1 unzipped it and then pasted in your Local Disk.下载后 Instantclient_11_1 解压缩它,然后粘贴到您的本地磁盘中。 And copy the path C:\\instantclient_11_1 and then set this path as your user variable & system variable.
并复制路径 C:\\instantclient_11_1 然后将此路径设置为您的用户变量和系统变量。 Note is that my code is working without setting path variable.
请注意,我的代码在没有设置路径变量的情况下工作。
Open your cmd and enter into SQL, create your schema following these commands打开你的 cmd 并输入 SQL,按照这些命令创建你的架构
grant connect,resource to dbname;授予连接,资源到 dbname;
Create table user_info and insert data into your table and commit out.创建表 user_info 并将数据插入表中并提交。 Note: you must commit your data either data is not inserted.
注意:您必须提交数据,否则不会插入数据。
<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) : ' ').'</td>'; } print '</tr>'; } print '</table>';
Alright, folks.好吧,伙计们。
First , use首先,使用
<?php
phpinfo();
?>
and determine your PHP Version (located at the very top, eg 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:您需要的以下三个软件绝对至关重要:
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.希望这可以帮助。
I installed Wamp & expected everything to work out of the box.我安装了 Wamp 并希望一切都能开箱即用。 Not so.
不是这样。 I have 2 Oracle clients on my x64 Windows machine (instant and full).
我的 x64 Windows 机器上有 2 个 Oracle 客户端(即时和完整)。 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.
如果其他人有类似的设置,诀窍是确保即时客户端 (a) 在您的 Path 环境变量中,并且 (b) 在 Path 变量中的完整客户端之前。 There's a really brief section on Windows here but it gave the answer.
有Windows上的真正简短的章节在这里,但它给出了答案。
try this尝试这个
in the php.ini file uncomment this在 php.ini 文件中取消注释这个
extension_dir = "./"
"remove semicolon" extension_dir = "./"
"去掉分号"
Download from Instant Client for Microsoft Windows (x64) and extract the files below to "c:\\oracle":从适用于 Microsoft Windows (x64) 的 Instant Client 下载并将以下文件解压缩到“c:\\oracle”:
instantclient-basic-windows.x64-12.1.0.2.0.zip Instantclient-basic-windows.x64-12.1.0.2.0.zip
instantclient-sqlplus-windows.x64-12.1.0.2.0.zip Instantclient-sqlplus-windows.x64-12.1.0.2.0.zip
instantclient-sdk-windows.x64-12.1.0.2.0.zip This will create the following folder "C:\\Oracle\\instantclient_12_1". Instantclient-sdk-windows.x64-12.1.0.2.0.zip 这将创建以下文件夹“C:\\Oracle\\instantclient_12_1”。
Finally, add the "C:\\Oracle\\instantclient_12_1" folder to the PATH enviroment variable, placing it on the leftmost place.最后,将“C:\\Oracle\\instantclient_12_1”文件夹添加到PATH环境变量中,放在最左边的地方。
Then Restart your server.然后重启你的服务器。
I know I am too late to reply here but I tried everything and nothing worked for me for two days then I found this video .我知道我在这里回复为时已晚,但我尝试了所有方法,但两天没有任何效果,然后我找到了这个视频。 It solved my problem .
它解决了我的问题。 So I am sharing this with everybody .
所以我把这个分享给大家。 Happy coding :-)
快乐编码:-)
1 - The first step is to identify the right instant client for your xampp or wampp or lampp installation through checking PHP details from phpinfo. 1 - 第一步是通过检查 phpinfo 中的 PHP 详细信息,为您的 xampp 或 wampp 或 lampp 安装确定正确的即时客户端。 Create a simple php file and add the code below and preview on your browser.
创建一个简单的 php 文件并添加以下代码并在浏览器上预览。
<?php
phpinfo();
?>
phpinfo() details phpinfo() 详细信息
2 - Go to https://www.oracle.com/database/technologies/instant-client/downloads.html and download the right instant client (base package and sdk) for your architecture (32bit or 64bit) 2 - 转到https://www.oracle.com/database/technologies/instant-client/downloads.html并为您的架构(32 位或 64 位)下载正确的即时客户端(基本包和 sdk)
Instant client package - basic即时客户端包 - 基本
Instant client package - SDK即时客户端包 - SDK
3 - Extract instantclient to your preferred directory and add the path to your environment variables. 3 - 将 Instantclient 解压缩到您的首选目录并将路径添加到您的环境变量中。
4 - Go to php.ini and enable oci8
extension by removing the ;
4 - 转到 php.ini 并通过删除
;
来启用oci8
扩展;
at the start of the line.在行的开头。 Look for this line
寻找这条线
;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client
Refactor to重构为
extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client
5 - Restart your PC 5 - 重新启动您的电脑
6 - Check your phpinfo (The page you created on step 1). 6 - 检查您的 phpinfo(您在第 1 步中创建的页面)。 You should see the details below:
您应该会看到以下详细信息:
Setting the NLS_LANG Environment Variable for Oracle Databases (By - Jaydev) Follow this procedure to set the NLS_LANG environment variable for Oracle databases. 为Oracle数据库设置NLS_LANG环境变量(By - Jaydev)按照以下过程为Oracle数据库设置NLS_LANG环境变量。 To set the NLS LANG environment variable for Oracle databases
为Oracle数据库设置NLS LANG环境变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.