I am trying to connect to an oracle database using php. When I try to connect by connection string/descriptor, it connects just fine, but when I try to connect using a tns name, the whole thing stops and chrome shows a blank error page ERR_CONNECTION_RESER
. I see the failed response and it is 0 bytes, no header, no body... nothing.
here is the code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$connStr = "Some connection <string> copied from tnsnames.ora";
//$connStr = "Some connection <name> copied from tnsnames.ora";
try
{
$conn = oci_connect('dev', '12345678', $connStr, 'utf8');
if (!$conn)
{
$err = oci_error();
var_dump($err);
}
oci_close($conn);
echo "Success";
}
catch(Exception $e)
{
$err = oci_error();
var_dump($err);
var_dump($e);
}
I checked and my php can see ORACLE_HOME TNS_ADMIN and they are pointing to the right direction. I am using Windows 7 amd64 PHP 5.6.13 TS VC11 Apache 2.4.16 VC14 Instant Client 12.1.0.2
After hours spent and sleeps not slept on this issue, I found the solution.
I have an sqlnet.ora file that specifies timeouts and other network properties. Our databases recently joined the firm's domain and the problem was with this line:
Previously
NAMES.DIRECTORY_PATH= (HOSTNAME, TNSNAMES, ONAMES, EZCONNECT, LDAP)
#########
Solution
NAMES.DIRECTORY_PATH= (HOSTNAME, TNSNAMES, ONAMES, EZCONNECT, LDAP)
NAMES.DEFAULT_DOMAIN = FIRM.DOMAIN