First of all I know there are many questions posted for the same issue. I have tried every thing but couldn't get it to work. I am trying to connect to SQL Server using PHP. I've configured FreeTDS and unixODBC correctly. I tried tsql, isql and telnet and it connects to the server without an issue. But when I try to connect using PHP and execute the script in browser, it gives me this error:
SQLSTATE[08S01] SQLDriverConnect: 20009 [unixODBC][FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist
PHP Script
<?php
putenv('ODBCSYSINI=/etc');
putenv('ODBCINI=/etc/odbc.ini');
try {
$dbh = new PDO('odbc:U18958173','<USER_NAME>','<PASSWORD>');
} catch (PDOException $exception) {
echo $exception->getMessage();
exit;
}
echo var_dump($dbh);
unset($dbh);
freetds.conf
[U18958173]
host = <SERVER_IP>
instance = SQLEXPRESS
#port = 1433
tds version = auto
client charset = UTF-8
odbc.ini
[U18958173]
Driver = FreeTDS
Description = MSSQL database for my nice app
Servername = U18958173
UserName = <USER_NAME>
Password = <PASSWORD>
Database = <DATABASE>
TDS_VERSION = auto
When I browse my PHP script in browser it gives me the error I mentioned above. Please help me, I've been searching for the solution for the last 3 days. Thank you.