I have followed this solution for what seems to be the exact same problem, however I am not having as much success as I had hoped. I set up the required config files for PDO_ODBC, unixODBC and FreeTDS packages:
First by specifiying the host in
/etc/freetds.conf
:[mssql] host = DBHost port = 1433 tds version = 7.3
Then by specifying the FreeTDS driver location in
/etc/odbcinst.ini
:[freetds] Description = Ms SQL database access with Free TDS Driver64 = /usr/lib64/libtdsodbc.so.0 Setup64 = /usr/lib64/libtdsS.so.2 FileUsage = 1 UsageCount = 1
Then by specifying the DSN in
/etc/odbc.ini
:[mssql] Description = mssql server Driver = FreeTDS Database = CET_PhonesDB ServerName = mssql TDS_Version = 7.3
Finally here is my PHP:
try {
$pdo = new PDO('odbc:mssql', 'dbuser', 'dbpass');
}
catch(Exception $e){
echo $e->getMessage();
}
which returns: "SQLSTATE[08S01] SQLConnect: 20009 [unixODBC][FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist".
I've tried troubleshooting using $tsql -S mssql -U dbuser -P dbpass
(which tests the FreeTDS) and $isql mssql dbuser dbpass
(Which tests the unixODBC) both of which connect successfully. This leads me to believe that the problem is with PDO_ODBC or something else in the PHP configuration. Any help is greatly appreciated :)