PDL sqlsrv is in phpinfo but does not work

0

I'm trying to access a SQL server from another Ubuntu 16.04 server using PHP, I made the entire drive installation process informed by Microsoft's own website and in phpinfo the installed drive is shown as shown in the images, however when I go connecting to the bank shows the error:

  

Error !: SQLSTATE [HYT00]: [unixODBC] [Microsoft] [ODBC Driver 13 for SQL Server] Login timeout expired

  

PHPVersion7.1.3-2+deb.sury.org~xenial+1

Thefollowingistheconnectioncode:

try{$db_host='HOST';$db_username='USER';$db_password='PASS';//$dsn="mysql:dbname=test;host={$db_host}";
    $dsn = "sqlsrv:database=test;server={$db_host}";

    $conn = new PDO($dsn, $db_username, $db_password);
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
    
asked by anonymous 24.03.2017 / 14:12

1 answer

1

Thanks to everyone who helped me here, after re-creating the /opt folder on the server (which by the way still did not understand how it was deleted), and reinstalling the drive this link helped me: link

After that the problem was that my SQL Server was not using the default post, I used neststat to check the correct port. And that's the final code:

try {
    $db_host = 'HOST,PORT';
    $db_username = 'USER';
    $db_password = 'PASS';
    $db_database = 'DATABASE';

    $dsn = "sqlsrv:database={$db_database};server={$db_host}";

    $conn = new PDO($dsn, $db_username, $db_password);
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}

if ($conn) {
    echo "Connected!";
} else {
    echo "Error";
}
    
24.03.2017 / 20:01