简体   繁体   中英

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.

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. From database side I have added TNS_ADMIN and ORACLE_HOME to path variable.

This is my php script:

    $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

the string is the same in the tsnames.ora and the listener is running. I checked that in 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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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