Ocilogon can't login remote oracle server?But sqlplus works fine!


php 4.0.1pl2
oracle 8i
web server: NES 3.6
os : Solaris 2.6

Oracle is resident at another server,its sid is 'webdb' and
service name is 'net.db.host.com'

I set up oracle 8i client on the web server,and configure the
netec which test ok.

When I use tnsping and sqlplus,all works well,
for example:
tnsping net
tnsping db
tnsping net.db.host.com
sqlpus scott/tiger@net

But when I use php4 with oci8 support,all don't work!

This is the example code and error message:

source code:

<?
putenv("ORACLE_SID=webdb");
putenv("ORACLE_HOME=/data/oracle/app/8.1.5");
putenv("NLS_LANG=american.america.US7ASCII");

      $conn = OCIpLogon("scott/tiger@net.db.host.com","");

if(!$conn)$conn=OCIpLogon("scott/tiger@webdb","");
if(!$conn)$conn=OCIpLogon("scott/tiger@net","");

if(!$conn)$conn=OCIpLogon("scott@net.db.host.com","tiger");
if(!$conn)$conn=OCIpLogon("scott@webdb","tiger");
if(!$conn)$conn=OCIpLogon("scott@net","tiger");

if(!$conn)$conn=OCIpLogon("scott","tiger","net.db.host.com");
if(!$conn)$conn=OCIpLogon("scott","tiger","webdb");
if(!$conn)$conn=OCIpLogon("scott","tiger","net");

if($conn)
echo "sucessful!";
else
echo "<font color=red>Connect to database failed!";

?>

The error message :

Warning: _oci_open_server: ORA-12545: Connect failed because target host or object does not exist in /data/php/z.php on line 6

Warning: _oci_open_server: ORA-12545: Connect failed because target host or object does not exist in /data/php/z.php on line 7

Warning: _oci_open_server: ORA-12545: Connect failed because target host or object does not exist in /data/php/z.php on line 8

Warning: _oci_open_server: ORA-12545: Connect failed because target host or object does not exist in /data/php/z.php on line 10

Warning: _oci_open_server: ORA-12545: Connect failed because target host or object does not exist in /data/php/z.php on line 11

Warning: _oci_open_server: ORA-12545: Connect failed because target host or object does not exist in /data/php/z.php on line 12

Warning: _oci_open_server: ORA-12154: TNS:could not resolve service name in /data/php/z.php on line 14

Warning: _oci_open_server: ORA-12154: TNS:could not resolve service name in /data/php/z.php on line 15

Warning: _oci_open_server: ORA-12154: TNS:could not resolve service name in /data/php/z.php on line 16

Connect to database failed!

This is the tnsnames.ora file on web server

TNSNAMES.ORA Configuration File:/data/oracle/app/8.1.5/network/admin/tnsnames.ora

Generated by Oracle Net8 Assistant

NET =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = db.host.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = net.db.host.com)
)
)


This is the listener.ora on the oracle server

LISTENER.ORA Configuration File:/oracle/app/8.1.5/network/admin/liste

Generated by Oracle Net8 Assistant

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
(PROTOCOL_STACK =
(PRESENTATION = TTC)
(SESSION = NS)
)
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.13)(PORT = 2481))
(PROTOCOL_STACK =
(PRESENTATION = GIOP)
(SESSION = RAW)
)
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db.host.com)(PORT = 1521))
(PROTOCOL_STACK =
(PRESENTATION = TTC)
(SESSION = NS)
)
)
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /oracle/app/8.1.5)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = net.db.host.com)
(ORACLE_HOME = /oracle/app/8.1.5)
(SID_NAME = webdb)
)

)

    8 days later

    Hi bet-wolf,

    we are facing exactly the same problem. Have you found a solution to it.

    Regards

    Kirti

      $conn = OCIpLogon("scott/tiger@net.db.host.com","");
      try this call:
      $conn = OCIpLogon("scott","tiger","DBALIAS");
      where dbalias an alias (TCP) you have created into tnanames.ora:

      ex. ALIAS 😮RACLE

      ORACLE =
      (DESCRIPTION =
      (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = REMOTE_MACHINE_IP_ADDRESS)(PORT = 1521))
      )
      (CONNECT_DATA =
      (SERVICE_NAME = REMOTEMACHINE_SERVICE_NAME)

      where
      REMOTEMACHINE_SERVICE_NAME : look into init.ora file (you will see a "service_name")
      )
      )

        Hi,

        The configuration on our side is exactly the same as given above but still it gives me th following message :

        C:\php\php4>php "c:\program files\apache group\apache\htdocs\ora.php3"
        X-Powered-By: PHP/4.0.1-dev
        Content-type: text/html

        SACHIN<br>
        <b>Warning</b>: oci_open_server: ORA-12203: TNS:unable to connect to destinati
        on
        in <b>c:\program files\apache group\apache\htdocs\ora.php3</b> on line <b>5</b>
        <br>
        OCIDebug:
        oci_open_server: FAILURE -> CLEANUP called<br>
        OCIDebug: START oci_close_server: detaching conn=0 dbname=<br>
        OCIDebug: oci_do_connect: FAILURE -> CLEANUP called<br>
        OCIDebug: START
        oci_conn_list_dtor: id=0<br>
        OCIDebug: END _oci_conn_list_dtor: id=0<br>
        OCIDebug: START php_rshutdown_oci<br>
        OCIDebug: END php_rshutdown_oci<br>
        OCIDebug: START php_mshutdown_oci<br>
        OCIDebug: END php_mshutdown_oci<br>

        Regards

        Kirti

               THIS IS NOT NORMAL.

          FIRST OF ALL YOU HAVE FAILED TO LOAD A MODULE.
          THIS IS HAPPENED WHEN THE STRING:

          X-Powered-By: PHP/4.0.1-dev
          Content-type: text/html

          APPEARED IN THE FIRST LINE.
          MAYBE THIS MODULE IS PHP_OCI.DLL!!!

          NEVER START APACHE FORM MSDOS IN WIN32. THERE IS A PROBLEM WITH PHP_OCI.DLL
          START APACHE AS SERVICE.

          THE OTHER PROBLEM IS THA YOUR DEBUGER PRINTS:
          _oci_close_server: detaching conn=0 dbname=<BR>

          WHERE IS THE "DBNAME" VALUE ????

          YOU SAID THAT YOU ALREADY TRIED SUCCESFULLY TO CONNECT REMOTELY USING SQL/PLUS WITH THE PARAMETERS:

          FROM MSDOS TRY:
          SQLPLUS SCOTT/TIGER@REMOTEDBALIAS
          IF SUCCESS THEN ?????????


          IN GENERAL THIS PROBLEM HAPPENED :

          • because you are using a name descriptor other that local.
            Example: if descriptor is :world
            in tnsnames.ora you should have
            oracle.world = (description ....
            AND NOT
            oracle = (description ....
            (THIS IS FOR ORACLE VERSIONS PREVIOUS TO 8I)

          • YOU HAVE INSTALLED ORACLE SQLNET FOR ORACLE 8I BUT REMOTE DATABASE IS AT MAX 8.0.5

          • you have installed SQLNet in different locations. This happened when you have installed other oracle products on the same machine.

          YOU ARE USING APACHE?
          TRY TO START APACHE AS SERVICE

            I solved this problem,and I hopes it can help you some.

            I run the web server as nobody on the Solaris 2.6 system.
            But the nobody user can't acess the file tnsnames.ora,which is critical to the
            oracle client.So the program encounte the tns-12154 error.
            After I add the nobody user into dba group,all fine.

              This is not problem my friend,

              It's unix (and linux)characteristic.
              You should already know that :-(

                Hi

                I am able to connect from dos prompt if i type sqlplus sccot/tiger. Also my tnsnames.ora has world specified in it. The database that i am using is of version 8.1.5
                I still get the following error;

                Note : I have used the OCIInternalDebug()

                C:\php\php4>php "c:\program files\apache group\apache\htdocs\ora.php3"
                X-Powered-By: PHP/4.0.1-dev
                Content-type: text/html

                SACHIN<br>
                <b>Warning</b>: oci_open_server: ORA-12203: TNS:unable to connect to destinati
                on
                in <b>c:\program files\apache group\apache\htdocs\ora.php3</b> on line <b>5</b>
                <br>
                OCIDebug:
                oci_open_server: FAILURE -> CLEANUP called<br>
                OCIDebug: START oci_close_server: detaching conn=0 dbname=<br>
                OCIDebug: oci_do_connect: FAILURE -> CLEANUP called<br>
                OCIDebug: START
                oci_conn_list_dtor: id=0<br>
                OCIDebug: END _oci_conn_list_dtor: id=0<br>
                OCIDebug: START php_rshutdown_oci<br>
                OCIDebug: END php_rshutdown_oci<br>
                OCIDebug: START php_mshutdown_oci<br>
                OCIDebug: END php_mshutdown_oci<br>

                C:\php\php4>

                  2 months later

                  Hello,

                  Having the same problem to connect to an instance of oracle.

                  This is the message i got on OCILOGON :

                  Warning: _oci_open_server: ORA-12560: TNS : erreur d'adaptateur de protocole in d:\apache\sites\index.php on line 7

                  Does someone has the solution ???

                  thank you very much...

                  hervé

                    6 months later

                    I can't connect to remote database to.
                    What I checked:
                    1. Module OCI seems to be loaded (PHP knows functions' names)
                    2. Apache was started as a service under WIN NT
                    3. Other apllications (Oracle Forms/SQL PLUS) work correctly using TNSNAMES.ORA
                    4. PHP has access to TNSNAMES.ORA (I can read file (function file("...\tnsnames.ora" works properly))

                    But I stinn get a message TNS could not resolve service name.

                    What else should I do or check?

                      a month later

                      I know this is an old thread and my problem is similar to the one above, but I was wondering which one is the function for nonpersistent? And why I am getting the following warning?

                      I am using OCILogon to connect, then disconnecting as soon as I get the information I need. But I'm getting these erratic TNS warning messages:

                      Warning: _oci_open_server: ORA-12154: TNS:could not resolve service name in /www/html/SQL/verify.php on line 12

                      Line 12 is where I am calling the OCILogon function. I say the message is erratic because I can reload the page 15 times and the query runs completely, but at some time x when I hit that reload button the one more time, I get the message. I'm wondering if I am doing something to mess up my ability to reach the service. And it's affecting my customers.

                      My DB guy says that we have our databases set up as .world. Do we need to put the webserver username in the tnsnames file or what? I am really confused by the differing responses and which reply is for which error message.

                      Thanks in advance for your advice.
                      Frog

                        dont use putenv() to set the environment.

                        the environmental vars are needed for the initialisation of the oci8 interface BEFORE you start the apache.
                        that means, put in your /etc/rc.d/apache
                        startupscript

                        the lines exporting the environment e.g.

                        export NLS_LANG=german_germany.WE8DEC
                        export ORACLE_HOME=/u01/8.1.6/

                        ...

                          We aren't using Oracle 8. Does that make a difference?

                            iam not really sure, but the oci7 api works imho in the same ways...

                              2 months later

                              The problem is that NES can't find oracle directories, because it can't read it from the shell environment.

                              Copy the variables from your environment to "start" file of your server instance. In my server is:
                              ORACLE_BASE=/u01; export ORACLE_BASE
                              ORACLE_HOME=/u01/oracle816; export ORACLE_HOME
                              ORACLE_SID=database; export ORACLE_SID

                              It should be ok

                                I believe that I have been getting this error and getting it inconsistently because I have two servers working together (load balanced) and one of them was not getting its TNSnames file updated as we needed it to be. So when a different server wold respond, I would get sometimes a successful query and sometimes a failure with the error message above. I hope that this helps someone else with a similar error.

                                  3 months later

                                  I am using IIS5 on win2000, using PHP with ISAPI ... I have no problem to connect to the database.

                                  so I move the same TNSNAMES.ORA to IIS4 web server on NT, using PHP ISAPI mode....
                                  Great, it works...

                                  Then, I change PHP from ISAPI into CGI mode...

                                  Not great...everything is not working..

                                  I have the message...

                                  Warning: _oci_open_server: ORA-12154: TNS:could not resolve service name

                                  Also, in the debug mode....showing nothing

                                  conn=0 dbname=

                                  so I found out some one posting a message on php.net ...
                                  He said make sure you don\\'t have M in your tnsname.ora...

                                  So I remove all the M in TNSNAMES.ORA
                                  follow it....

                                  the debug mode shows

                                  detaching conn=0 dbname=test

                                  Anyway, even ISAPI works....I still want to know why CGI does not work? My boss prefer me to use CGI mode php.

                                    Hello,

                                    Ya!!
                                    I found out the answer.

                                    Make sure BOTH of the files
                                    ===> TNSNAMES.ORA <====
                                    ===> SQLNET.ORA <====

                                    CAN NOT HAVE "M" ....

                                    Then it will work..🙂

                                    ==========================================
                                    The information is from
                                    http://ee.php.net/manual/it/ref.oci8.php

                                      a month later

                                      For a couple of days now I've been trying to establish an Oracle connection with
                                      no luck. I have the same problem as described above.

                                      My environment is:

                                      Win NT -Local
                                      Apache 1.3.20 -Local
                                      PHP 4.0.6 CGI -Local
                                      Oracle 7.3 - Remote (Solaris 5.6)

                                      I get 2 types of errors:
                                      1) ORA-12154: TNS:could not resolve service name
                                      2) ORA-03121: no interface driver connected

                                      I get the first error when my connect statement looks like this:
                                      Ora_Logon("user@db.world","passwd");

                                      The second error comes up when I use the following connect statement:
                                      Ora_Logon("user","passwd");

                                      I have verified my tnsnames.ora and it looks fine since I can connect to Oracle through SQL*Plus. I got rid of the CR, as I saw
                                      in one of the posts that CR might be messing this up. It seems PHP is not able to find nor use tnsnames.ora.

                                      My phpinfo() shows Oracle-Support as enabled. I created a direcotry called
                                      extensions in the root php directory and dropped php_oracle.dll in it, then I
                                      uncommented: extension=php_oracle.dll in my php.ini file and verified:
                                      extension_dir = "c:\php\extensions"
                                      Is php_oracle.dll the only required dll for getting PHP and Oracle 7.3 to work?

                                      Any suggestions will be strongly appreciated. Thank you.

                                      Here is my code:

                                      <?
                                      putenv("ORACLE_SID=db.world");
                                      putenv("ORACLE_HOME=C:\ORANT");
                                      putenv("TNS_ADMIN=C:\ORANT\NETWORK\ADMIN");

                                      if(!($connection=Ora_Logon("user@db.world","passwd")))
                                      {
                                      echo "Couldn't logon to database.";
                                      exit();
                                      }
                                      else
                                      echo "Connected to database";

                                      Ora_Logoff($connection);
                                      ?>

                                        putenv("ORACLE_SID=db.world");
                                        putenv("ORACLE_HOME=C:\ORANT");

                                        putebnv will not work.
                                        environment must be set before apache starts. (in apache startup skript)