I'm running PHP 5.5 on CentOS 6 trying to connect to a MS SQL Server database via PDO. I have searched through about 20 different answers to the same error message and tried every one of them here on SO. When I attempt to connect from PDO I get the following error:
SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)
I am able to connect through FreeTDS on the command line with no issue at all:
TDSVER=7.0 tsql -H 192.168.5.57 -p 1433 -U testuser
I tried setting tds version = 7.0
in freetds.conf
and still get the same error.
I've tried connecting to different MS SQL Servers and get the same thing every time. I've tried this same code on a Rackspace Cloud server with no issues. So something between PDO/PHP and FreeTDS doesn't seem to be talking correctly, but I am at a loss of how to track this down.
try {
$hostname = '192.168.5.57:1433';
$dbname = 'Test';
$username = 'testuser';
$password = 'thisismypassword';
$db = new PDO("dblib:host=$hostname;dbname=$dbname","$username","$password");
} catch (PDOException $e) {
echo 'Failed to get DB handle: ' . $e->getMessage();
}