1
I’m trying to connect to a SQL Server database using PHP, but the operation is timed out.
Using SSMS (Management Studio) with the same information as the PHP string, it is possible to connect normally in the database.
PHP:
$serverName = "servidor"; $connectionInfo = array("Database" => "database", "UID" => "usuario", "PWD" => "senha"); $conn = sqlsrv_connect($serverName, $connectionInfo); if (!$conn) die( print_r( sqlsrv_errors(), true));
Error:
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 258 [code] => 258 [2] => [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: The wait operation timed out. [message] => [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: The wait operation timed out. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired [message] => [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 258 [code] => 258 [2] => [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [message] => [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. ) )
I’m using the PHP 7.2.7
and Microsoft Driver 5.3 para PHP 7.2
, and everything is being run on IIS.
Would the error be because of the driver version or php version? Or it might be something related to this?
You are specifying the instance in
$serverName
? And the door?– João Martins
Yes, it is followed by: "ip_do_server,port". The code worked on my computer (running Windows 10, Apache and ODBC Driver 11), I don’t know if the OS or the ODBC driver influences it as well
– jcsantos