使用 PHP 连接到 Oracle

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

Connecting to Oracle using PHP

phporacle

提问by Ady Romantika

How do I connect to a remote Oracle database instance from PHP?

如何从 PHP 连接到远程 Oracle 数据库实例?

I need to query (read only) the remote Oracle database for some information; do I need to have an Oracle Instant Client installed?

我需要查询(只读)远程 Oracle 数据库以获取一些信息;我需要安装 Oracle Instant Client 吗?

Is the OCI extension for PHP enough?

PHP 的 OCI 扩展是否足够?

采纳答案by user15453

From PHP Manual

来自PHP 手册

  • You will need the Oracle client libraries to use this extension.

  • The most convenient way to install all the required files is to use Oracle Instant Client, which is available from Oracle's site

  • 您将需要 Oracle 客户端库才能使用此扩展。

  • 安装所有必需文件的最便捷方法是使用 Oracle Instant Client,该客户端可从Oracle 站点获得

回答by drnk

The best manual for using PHP with Oracle is Underground PHP Oracle Manual. Periodically updated. For example last update describe new cool OCI (Oracle Call Interface) features. I found it by accident and since then has never regretted. Start from that good manual.

在 Oracle 中使用 PHP 的最佳手册是Underground PHP Oracle Manual。定期更新。例如,上次更新描述了新的很酷的 OCI(Oracle 调用接口)特性。我偶然发现了它,从那时起从未后悔过。从那本好手册开始。

回答by Jroc

there are a couple of steps you need to go through to make this work.

要完成这项工作,您需要执行几个步骤。

First, you need to install the oracle driver for whatever OS you have. Then, create a DSN for odbc to use to connect the php function call to the oracle database. On windows, you can find this on the Control Panel -> ODBC Sources

首先,您需要为您拥有的任何操作系统安装 oracle 驱动程序。然后,为odbc 创建一个DSN,用于将php 函数调用连接到oracle 数据库。在 Windows 上,您可以在控制面板 -> ODBC 源中找到它

Once you have done this, restart the DB, the web server and then you should be able to test it all with this:

完成此操作后,重新启动数据库、Web 服务器,然后您应该可以使用以下命令对其进行测试:

odbc_connect($dsn,$user,$pass);

odbc_connect($dsn,$user,$pass);

If you have linux, the same steps are needed but I'm not sure how you create a DSN in unix.

如果您使用 linux,则需要执行相同的步骤,但我不确定您如何在 unix 中创建 DSN。

回答by John Fiala

If you're attempting to connect to oracle on ubuntu with PHP, the following links have been more than helpful:

如果您尝试使用 PHP 连接到 ubuntu 上的 oracle,以下链接非常有用:

A) http://pecl.php.net/bugs/bug.php?id=9253

A) http://pecl.php.net/bugs/bug.php?id=9253

That's the real-workhorse one - it gives you just about all the data you need.

这才是真正的主力——它为您提供几乎所有您需要的数据。

B) http://fabrizioballiano.net/2008/01/26/how-to-install-php-pdo_oci-on-ubuntu-gutsy/

B) http://fabrizioballiano.net/2008/01/26/how-to-install-php-pdo_oci-on-ubuntu-gutsy/

This is also helpful for details of things that need to be installed for oracle to work with ubuntu.

这对于 oracle 与 ubuntu 一起工作需要安装的东西的细节也很有帮助。

If you're using it with PHP, you'll need to make sure that the TNS_ADMIN and ORACLE_HOME environment variables are available for apache's user - there's a file named 'envvars' in the apache2 directory where you can set these. (For my own ease of use, I have the two point to the same directory.)

如果您在 PHP 中使用它,您需要确保 apache 的用户可以使用 TNS_ADMIN 和 ORACLE_HOME 环境变量 - 在 apache2 目录中有一个名为“envvars”的文件,您可以在其中设置这些。(为了我自己的方便使用,我把两个指向同一个目录。)

回答by p4bl0

I saw this in the "Notes" section of the PHP documentation:

我在PHP 文档的“注释”部分看到了这一点:

Ifyou're using PHP with Oracle Instant Client, you can use easy connect naming method (...)

如果您将 PHP 与 Oracle Instant Client 一起使用,您可以使用简单的连接命名方法 (...)

So I think it's rather clear that you can connect to an Oracle DB without the Oracle Instant Client, using only the PHP Oracle extension.

所以我认为很明显你可以在没有 Oracle Instant Client 的情况下连接到 Oracle DB,只使用 PHP Oracle 扩展。