Error when connecting to MS SQL database using from Linux using PHP ODBC and FreeTDS

221 views Asked by At

I am trying to connect to a MS SQl server using PHP PDO with ODBC and FreeTSD, but when I use the code below I get the following error:

"SQLSTATE[08S01] SQLDriverConnect: 20009 [unixODBC][FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist"

try {

    $DSN = 'odbc:Driver={FreeTDS};
        Server=example.testtelecom.cloud\MGNA,1434;Database=Referrals;
        Trusted_Connection=yes';

    $dbconn = new PDO($DSN, $username, $pwd);
    
    $dbconn -> setattribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
    $dbconn -> setattribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


}catch (PDOException $e) {
    echo "Broke: ". $e->getMessage();
}

Related drivers taken from phpinfo (pre-installed by host):

  • PDO Driver for FreeTDS/Sybase DB-lib
  • PDO Driver for ODBC (unixODBC)
  • PDO drivers: dblib, firebird, mysql, odbc, pgsql, sqlite

My hosting provider said that the necessary drivers etc come pre-installed but would not give much more info other than that. I am not sure if there is a configuration step I am missing or if it's just an error in my code.

0

There are 0 answers