Oh what a fool I am (Oracle/PHP connection)
| From: | Andy Hoffman | Date: | Fri, 03 Nov 2000 15:24:55 +0000 |
| Subject: | Oh what a fool I am (Oracle/PHP connection) | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-3668@lists.php.net to get a copy of this message | ||
Folks,
A bright new light has dawned in the "figuring out how to
use oci8 & php". For a while, Vince and I have been helping
folks get oci8 working under php4... well, all that time, I
was maintaining that the php oci8 connection call (ocilogon
or ociplogon) had to be made with the following syntax
(based on the php manual, of course):
ocilogon("<username>", "<passwd>", "<SID>");
Replacing the username, password and SID, of course, to
match those specified in Net8 Assistant and the database
server. However, that's not quite right... and this was
brought to light by the good fortune of Mustafa Sari (a
student in Portugal whom I was assisting this week). We
were having the hardest time getting his Oracle 8.1.6 client
to connect within PHP, and one of the reasons, I thought,
was because his Service Name (left hand tree-view in Net8
Assistant) did not match the specified SID for that
particular database instance. I previously figured that the
Service Name prefix (mysid in mysid.world, for instance)
MUST match the SID (MYSID for this example) specified using
Release 8.0 Compatibility.
Well, from what Mustafa discovered today... 1) the Service
Name in the left panel does not necessarily have to match
the specified SID, and more importantly 2) the name used by
ocilogon (what was previously noted as SID) is in fact the
service name prefix and NOT the SID. Here's two examples of
tnsnames.ora files to demonstrate what I'm getting at
(connection code to follow)...
#1 - Service Name prefix matches SID
MYSID.WORLD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)
(HOST = someserver.mycompany.com)
(PORT = 1521))
)
(CONNECT_DATA =
(SID = MYSID)
)
)
#2 - Service Name prefix different than SID
TEST.WORLD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)
(HOST = someserver.mycompany.com)
(PORT = 1521))
)
(CONNECT_DATA =
(SID = MYSID)
)
)
In example #1, which was the previous "only works this way"
recommendation, the correct connection call would look like:
ocilogon("scott","tiger","MYSID");
... which looked like the normal way of connecting via an
SID, right? Well, for example #2, you would only be able to
connect successfully via this connection call:
ocilogon("scott","tiger","TEST");
And thus the discovery that indeed, ocilogon calls within
PHP are made using the Service Name prefix, and NOT the
SID. Test it and see for yourself, but we're definitely
chalking this one up as one of the trickier tricks in the
OCI8 wars. Just thought you all might like to know about
it. And if anyone finds anything different, or if I'm just
blowing smoke, let me know.
Vince, this is definitely one for the How-to... and thanks,
Mustafa! You definitely made my morning :)
--
Andy Hoffman
Web Developer
Bristol-Myers Squibb
email: andy.hoffman@bms.com