1
I’m trying to access an SQL Server server from another Ubuntu server 16.04 using PHP, I did the entire installation process of the drive informed by Microsoft’s own website and phpinfo is shown the drive installed as shown in the images, but when I connect to the bank is shown the error:
Error!: SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired
PHP Version 7.1.3-2+deb.sury.org~xenial+1
Follow the connection code:
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();
}
Are you using php7? could you put the connection code?
– rray
I am using PHP 7.1.3
– BrunoAgenor
If I’m not mistaken, it’s
sqlsrv
orodbc
, use this here to see the prefixes:var_dump(PDO::getAvailableDrivers());
– Edilson
array(2) { [0]=> string(6) "sqlsrv" [1]=> string(5) "mysql" }
– BrunoAgenor
@Brunoagenor in your connection is
mssql
, the correct would be:new PDO("sqlsrv:Server=localhost;Database={$db_host}", "{$db_username}", "{$db_password}");
. it is worth checking this out here also. And if you can remove the answer below, and necklaces here on the question would facilitate.– Edilson
Really @Edilson, put the sqlsrv and now a different message is being shown. > Error!: SQLSTATE[IMSSP]: An invalid keyword 'dbname' was specified in the DSN string.
– BrunoAgenor
Does not write
dbname
, writDatabase
even.– Edilson
Through the link you can see that and it was:
$dsn = "sqlsrv:database=test;server={$db_host}";
But I get a new error message:> Error!: SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 13 for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver 13 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
– BrunoAgenor
Shows the error as if the extension was not installed, but in phpinfo shows otherwise
– BrunoAgenor
download the requested drive and see what gives.
– Edilson
The problem is that I already followed all these steps, at the end the link leads to this tutorial:
https://download.microsoft.com/download/C/D/B/CDB0A3BB-600E-42ED-8D5E-E4630C905371/Linux_4.0_Install_Instructions.pdf
– BrunoAgenor
After a lot of research I realized that the folder
/opt
on the server had disappeared, I created it and installed the drive again, now another error is being shown:Error!: SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired
– BrunoAgenor
I usually use freetds to connect to sqlsrv, I have a container that I use to run sqlsrv, this is the link to the dockerfile that I use to create the image https://hub.docker.com/r/toninho09/laravel/~/dockerfile/
– Antonio
I was able to connect, thank you very much to everyone who helped me. The latter was solved by specifying the SQL Server port that was not running on the default port:
$db_host = 'HOST,PORT';
– BrunoAgenor
Okay, put the answer here to close.
– Edilson