Can't connect to SQL Server with PHP [closed]

5 hours ago 1
ARTICLE AD BOX

I need to get data from a SQL Server with PHP but can't connect to the server.

My connection is like this:

$serverName = "server\\instance, port"; $uid = "username"; $pwd = "password"; $databaseName = "database"; $connectionOptions = array( "UID"=>$uid, "PWD"=>$pwd, "Database"=>$databaseName); $conn = sqlsrv_connect($serverName, $connectionOptions);

I get the following response:

Database connection failed Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 2 [code] => 2 [2] => [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [2]. [message] => [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [2]. ) [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] => 2 [code] => 2 [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 would like to mention when connecting with SSMS from the same workstation to the same server the connection works perfectly. Also I can connect from the same workstation to the same server with MS Access application using OLEDB driver with the connection string:

connStr = "Provider=SQLOLEDB;Data Source=" & "server\instance,port" & ";Initial Catalog=" & "database" & ";User ID=" & "username" & ";Password=" & "password" & ";Trusted_Connection=No"

I read the related articles on stackoverflow.com but I didn't find any working solution.

Thanks in advance.

Read Entire Article