views:

18

answers:

1

I'm having all sorts of trouble...

Here is the code I'm using:

$c = OCILogon('user', 'pass', 'host');

I get the following error:

PHP Warning: ocilogon(): ociopen_server: Error while trying to retrieve text for error ORA-12514 in D:\Inetpub\wwwroot**\oracle.php on line 26

Anyone know what the hell I'm doing wrong?

It's PHP4, IIS6 btw. I've tried this on PHP5, IIS7 as well, no luck.

Thanks for any help I can get... :(

+1  A: 

You must have correctly configured TNSNAMES.ora file, where is stored information about connection to database. Oracle errorr ORA-12514 says:

TNS:listener does not currently know of service requested in connect descriptor

Function OCILogon have this syntax (I'am not PHP developer, so excuse me if I was not right):

resource oci_connect ( string $username , string $password [, string $connection_string [, string $character_set [, int $session_mode ]]] )

In your example is on third position parametr "host". But manual says "connectin string". This "connection string" must be coonfigured throught file $ORACLE_HOME/network/admin/tnsnames.ora file ($ORACLE_HOME is folder where is Oracle client installed).

TNSNAMES.ORA look like this(example):

TEST_DB = (DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (COMMUNITY = tcp.world)(PROTOCOL = TCP)(Host = 127.0.0.1)(Port = 1521)))(CONNECT_DATA = (SID = TESTDB_SID)))

Instead:

$c = OCILogon('user', 'pass', 'host');

You should use:

$c = OCILogon('user', 'pass', 'TEST_DB');

...TEST_DB is service name from tnsnames.ora file

And yet for complementing (my file $ORACLE_HOME/network/admin/sqlnet.ora look like this):

SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
NAME.DEFAULT_ZONE = world
NAMES.DEFAULT_DOMAIN = world

And finally PHP manual example (connection string can be inserted directly into variables in PHP):

<?php
$db ="(DESCRIPTION =
     (ADDRESS =
         (PROTOCOL = TCP)
         (HOST = HOSTNAMEHERE)
         (PORT = 1521)
     )
   (CONNECT_DATA = (SID = SIDNAMEHERE))
  )";

$odbc = ocilogon ('user', 'pass', $db) or die( "Could not connect to Oracle database!") or die (ocierror());
?>
Martin Mares