如何使用 PHP 连接到远程 Oracle 11g 数据库

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

How to connect to a remote Oracle 11g database using PHP

phporacleubuntu

提问by Dean-O

I have tried to make oci_connectwork, by following these directions, but I still get the error:

我试图oci_connect按照这些说明进行工作,但仍然出现错误:

ora-24408 could not generate unique server group name in test.php

ora-24408 无法在 test.php 中生成唯一的服务器组名

Here is my PHP snippet (with bogus IP):

这是我的 PHP 代码段(带有虚假 IP):

   $tns2 = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 123.123.123.123)(PORT = 1521)) (CONNECT_DATA = (SID = foo)))";
   if ($conn = oci_connect("username","pwd", $tns2))
   {
       echo "Connected to foo";
       oci_close($conn);
   }
   else
   {
       die("could not connect to foo");
   }

I use SQL Developer and can connect to this database just fine from this Ubuntu server. I also have Java applications that connect from this Ubuntu server to the remote Oracle database without any problems.

我使用 SQL Developer 并且可以从这个 Ubuntu 服务器很好地连接到这个数据库。我也有从这个 Ubuntu 服务器连接到远程 Oracle 数据库的 Java 应用程序,没有任何问题。

What am I missing to make PHP work?

我缺少什么才能使 PHP 工作?

I even did the phpinfo()and it showed the oci8 information.

我什至做了phpinfo(),它显示了 oci8 信息。

回答by Luigi Siri

Take a closer look to oci_connect.

仔细看看oci_connect

And try with this conection string: "123.123.123.123:1521/foo"

并尝试使用此连接字符串: "123.123.123.123:1521/foo"

$conn = oci_connect("username","pwd", "123.123.123.123:1521/foo");

Hope it helps.

希望能帮助到你。

回答by sandino

You can try something like this:

你可以尝试这样的事情:

define ('DB_USER','username');
define ('DB_PASS','pwd');
define ('DB_HOST', '123.123.123.123');
define ('DB_NAME', 'YOUR_DATABASE_NAME');
define ('CONST_DB_CHARSET_FOR_CONNECT','WE8ISO8859P15');
define ('DB_CONNECTION_STRING','\123.123.123.123/DBSCHEMA');//in localhost use ''


$conexion = oci_connect(DB_USER, DB_PASS,DB_CONNECTION_STRING,CONST_DB_CHARSET_FOR_CONNECT);

Just put the right value for: YOUR_DATABASE_NAME that's how I connect to remote oracle 11.g database.

只需输入正确的值:YOUR_DATABASE_NAME 这就是我连接到远程 oracle 11.g 数据库的方式。

Hope this helps you.

希望这对你有帮助。