Reputation: 53
I've got a coworkers system that will connect to oracle from php using the TNSNAME, but not with an easy connect string. The same easy connect string works from my system that is setup the same (seemingly)
We both have wamp 3.3.0, php 8.0.26. It's out of the box with zero configuration changes. We both have oracle client 19c. Mine is 64, his is 32bit. Our TNSNAMES and sqlnet files are identical. We both have TNSNAMES and sqlnet in C:/Path and have user and system level environmental variables for TNS_ADMIN = C:/Path
our TNS Entry is
ORCL.WORLD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCLSERV)
)
)
This code works below for me, but he gets: ORA-12154: TNS:could not resolve the connect identifier specified in C:\wamp64\www\foo.php on line 2
it seems like that means it's trying to parse the easy connect string as if it's a tnsname?
<?php
print oci_connect("username", "password", "//192.168.56.1:1521/ORCLSERV");
?>
I've tried different syntaxes for the easy connect string, with an without //, with and without the port.
However, this code works for him (and me):
<?php
print oci_connect("username", "password", "ORCL.WORLD");
?>
I'm not even sure what else to check. It's just baffling to me. I feel like I'm either going mad or making some really dumb, obvious mistake. Anyone have anything I should try?
Upvotes: 2
Views: 303
Reputation: 53
So the documentation says you can use easy connect string, or the TNSNAMES interchangeably. It doesn't mention any kind of setting to swap between the two methods, but there effectively is a setting.
The presence of a correctly setup TNSNAMES file effectively acts as a setting to force oci_connect() to only accept a TNSNAMES entry as the third parameter. This means, if you have TNSNAMES setup, and you have a third parameter of "//192.168.56.1:1521/ORCLSERV" it will search your TNSNAMES.ora file for a server called "//192.168.56.1:1521/ORCLSERV". Of course it won't find it and will issue "ORA-12154: TNS:could not resolve the connect identifier specified"
The reason our systems were working differently was because I didn't understand that WAMP/PHP uses the TNS_ADMIN set at the system level.
My TNSNAMES worked for sql developer, toad, sqlplus, etc. So I assumed it would be good for PHP too. I was mistaken. I had only setup the user TNS_ADMIN which worked for all the other apps, but PHP needed the system TNS_ADMIN set. So my oci_connect was in easy connect mode.
My co-workers system had setup both system and user TNS_ADMIN. So his PHP had TNSNAMES correct, and so his oci_connect used TNSNAMES.
Upvotes: 0