简体   繁体   English

使用php连接到oracle数据库时的oci_connect警告

[英]oci_connect warning when connecting to oracle Database with php

I have 2 days now trying to connect to a remote oracle database installed in a machine running with windows 7. 我现在有2天时间试图连接到运行Windows 7的计算机中安装的远程oracle数据库。

From PHP server side I installed wampserver and oracle instant client 11.2 and I enabled oci8 php extension, I have also added instant client folder to my path variable. 从PHP服务器端,我安装了wampserver和oracle Instant Client 11.2,并启用了oci8 php扩展名,我还将Instant Client文件夹添加到了path变量中。 From database side I have added TNS_ADMIN and ORACLE_HOME to path variable. 从数据库方面,我已将TNS_ADMIN和ORACLE_HOME添加到路径变量。

This is my php script: 这是我的PHP脚本:

    $db= "(DESCRIPTION =
              (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.43)(PORT = 1521))
              (CONNECT_DATA =
              (SERVER = DEDICATED)
                (SERVICE_NAME = hasdrubal)
              )
           )";
    $conn = oci_connect('SYSTEM', 'pass', $db);
    if (!$conn)
    {
       $e = oci_error();
      trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
    }
    else
    {
       die("connected");
    }

I always get error 我总是会出错

oci_connect ORA-12541: TNS:no listener oci_connect ORA-12541:TNS:无监听器

the string is the same in the tsnames.ora and the listener is running. tsnames.ora中的字符串相同,并且侦听器正在运行。 I checked that in services.msc. 我在services.msc中进行了检查。

Can you help me please? 你能帮我吗?

If you don't want to deal with TNS, then you can use an Easy Connect string as the 3rd parameter for oci_connect() , also mentioned in the oci_connect() documentation : 如果您不想处理TNS,则可以使用Easy Connect字符串作为oci_connect()的第三个参数,该参数也在oci_connect()文档中提到:

To use the Easy Connect naming method, PHP must be linked with
Oracle 10g or greater Client libraries.

The Easy Connect string for Oracle 10g is of the form:
[//]host_name[:port][/service_name].

From Oracle 11g, the syntax is:
[//]host_name[:port][/service_name][:server_type][/instance_name]

In your case it would be something like: 在您的情况下,它将类似于:

//192.168.1.43:1521/hasdrubal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM