Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Yet another failure to connect...

677573Dec 30 2008 — edited Jan 6 2009
I'm having a problem connecting PHP to Oracle that's had me pulling my hair our. I've set up PHP
with Oracle before and had no problems, but I'm at wit's end. I've searched the internet and while
I've found the same problem numerous times, none have worked for me. I've tried so many fixes I'm
starting to wonder how I'm ever going to back out of them when I find a working solution.

I'm running Windows XP, PHP 5.2.8, Oracle Client 10.2.0.4, and Apache 2.2.11. The OCI install went
fairly smooth and OCI8 appears in PHP Info. TNS is set to first check the enterprise OID Server and
then my local TNSNAME.ORA file, but the connection info should be found in the TNSNAMES.ORA. SQLPLUS
and TNSPING are both able to locate the target database. TNS_ADMIN is set to point to the directory
containing my TNSNAMES.ORA file. Following various things I've seen on the web, I've copied the three
OCI dll files damned near everywhere.

---------------------------------------------------------------------------

My first take on the code was...

<?php
$username = "xxxxx";
$password = 'xxxxxxx';
$database = 'xxxxxxxx';

print "Username = " . $username . "\n";
echo "Password = " . $password . "\n";
echo "Database = " . $database . "\n\n";

if ($db_conn = @oci_connect($username, $password, $database))
{
echo "Successful Connection\n";
echo "Value of connection db_conn is " . $db_conn . "\n\n";
oci_close($db);
}
else
{
echo "Connection Failed\n";
echo "Value of connection db_conn is " . $db_conn . "\n\n";
}
?>

Username = xxxxx
Password = xxxxxxx
Database = xxxxxxxx

Connection Failed
Value of connection db_conn is

------------------------------------------------------------------------------

I'm not familiar with the @ sign in PHP so I removed it.

<?php
$username = "xxxxx";
$password = 'xxxxxxx';
$database = 'xxxxxxxx';

print "Username = " . $username . "\n";
echo "Password = " . $password . "\n";
echo "Database = " . $database . "\n\n";

if ($db_conn = oci_connect($username, $password, $database))
{
echo "Successful Connection\n";
echo "Value of connection db_conn is " . $db_conn . "\n\n";
oci_close($db);
}
else
{
echo "Connection Failed\n";
echo "Value of connection db_conn is " . $db_conn . "\n\n";
}
?>

Username = xxxxx
Password = xxxxxxx
Database = xxxxxxxx

Connection Failed
Value of connection db_conn is

PHP Warning: oci_connect(): OCIEnvNlsCreate() failed. There is something
wrong with your system - please check that PATH includes the directory with
Oracle Instant Client libraries in C:\src\php\oratest.php on line 10

--------------------------------------------------------------------------------

I added c:\oracle\product\10.2.0\client\LIB to the %PATH% variable... And got
the same error. I then made the following change trying to make sure that
TNS_ADMIN was availavle, even though I'd set it previously in System Variables.

<?php
$username = "xxxxx";
$password = 'xxxxxxx';
$database = 'xxxxxxxx';

print "Username = " . $username . "\n";
echo "Password = " . $password . "\n";
echo "Database = " . $database . "\n\n";

PutEnv("TNS_ADMIN=C:/oracle/product/10.2.0/client/NETWORK/ADMIN");
$tns = getenv('TNS_ADMIN');
echo "TNS_ADMIN = " . $tns . "\n\n";

if ($db_conn = @oci_connect($username, $password, $database))
{
echo "Successful Connection\n";
echo "Value of connection db_conn is " . $db_conn . "\n\n";
oci_close($db);
}
else
{
echo "Connection Failed\n";
echo "Value of connection db_conn is " . $db_conn . "\n\n";
}
?>


Username = xxxxx
Password = xxxxxxx
Database = xxxxxxxx

TNS_ADMIN = C:/oracle/product/10.2.0/client/NETWORK/ADMIN

Connection Failed
Value of connection db_conn is


---------------------------------------------------------------------------------

After that I changed the syntax of the oci_connect command as follows... and yes, 1522
is correct for us.

<?php
$username = "xxxxx";
$password = 'xxxxxxx';
$database = 'xxxxxxxx';

print "Username = " . $username . "\n";
echo "Password = " . $password . "\n";
echo "Database = " . $database . "\n\n";

PutEnv("TNS_ADMIN=C:/oracle/product/10.2.0/client/NETWORK/ADMIN");
$tns = getenv('TNS_ADMIN');
echo "TNS_ADMIN = " . $tns . "\n\n";

if ($db_conn = @oci_connect($username, $password, '//xxxxxx-xxx.xxxx.xxxxxx.xxxxx:1522/xxxxxxxx'))
{
echo "Successful Connection\n";
echo "Value of connection db_conn is " . $db_conn . "\n\n";
oci_close($db);
}
else
{
echo "Connection Failed\n";
echo "Value of connection db_conn is " . $db_conn . "\n\n";
}
?>

Username = xxxxx
Password = xxxxxxx
Database = xxxxxxxx

TNS_ADMIN = C:/oracle/product/10.2.0/client/NETWORK/ADMIN

Connection Failed
Value of connection db_conn is

------------------------------------------------------------------------------------

And I tried the following full specification in my PHP code...

<?php
$username = "xxxxx";
$password = 'xxxxxxx';
$database = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST = xxxxxxx-xxx.xxxx.xxxxxx.xxx)(PORT=1522))(CONNECT_DATA=(SERVER=DEDICATED)(SID=xxxxxxx)))";

print "Username = " . $username . "\n";
echo "Password = " . $password . "\n";
echo "Database = " . $database . "\n\n";

if ($db_conn = @oci_connect($username, $password, $database))
{
echo "Successful Connection\n";
echo "Value of connection db_conn is " . $db_conn . "\n\n";
oci_close($db);
}
else
{
echo "Connection Failed\n";
echo "Value of connection db_conn is " . $db_conn . "\n\n";
}
?>

Username = xxxxx
Password = xxxxxxx
Database = (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST = xxxxxxx-xxx.xxxx.xxxxxx.xxx)(PORT=1522))(CONNECT_DATA=(SERVER=DEDICATED)(SID=xxxxxxx)))

Connection Failed
Value of connection db_conn is

------------------------------------------------------------------------------------


The only explanation that makes any sense is that OCI8 in PHP is not reading TNS data,
but I can't think of why. I'm sorry this is so long but I wanted to try to be complete.
If anyone has any suggestions for how I can continue to try to diagnose this, I'd really
appreciate it because I'm out of ideas and web sites to check. Thanks.


Larry Krigbaum
krigbaum@purdue.edu
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 3 2009
Added on Dec 30 2008
13 comments
3,386 views