I am trying to use PHP to connect to SQL Server 2008. I keep getting the following message.
Unable to connect.
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 2 [code] => 2 [2] => [Microsoft][SQL Native Client]Named Pipes Provider: Could not open a connection to SQL Server [2]. [message] => [Microsoft][SQL Native Client]Named Pipes Provider: Could not open a connection to SQL Server [2]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Native Client]Login timeout expired [message] => [Microsoft][SQL Native Client]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 2 [code] => 2 [2] => [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. [message] => [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. ) )
Here is the code I have been using.
I have checked that remote connections are allowed for the server by right clicking on the instance name in SSMS, I then click on Properties and went to Connections. Allow Remote connections to this server is checked. Also I have installed the Native Driver for PHP. I am using the PHP Driver for Windows which was installed by the Web Platform Installer and confirmed in phpinfo() that sqlsrv was present. I have tried using (local), MARIS-IDX01/MARISIDX, ./MARISIDX, and localhost/MARISIDX. All yield the same result.
I have been scouring the internet looking for solutions but nothing has been able to help with my problem. Any ideas please???.
Thanks in advance
Unable to connect.
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 2 [code] => 2 [2] => [Microsoft][SQL Native Client]Named Pipes Provider: Could not open a connection to SQL Server [2]. [message] => [Microsoft][SQL Native Client]Named Pipes Provider: Could not open a connection to SQL Server [2]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Native Client]Login timeout expired [message] => [Microsoft][SQL Native Client]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 2 [code] => 2 [2] => [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. [message] => [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. ) )
Here is the code I have been using.
<?PHP /* Specify the server and connection string attributes. */ $serverName = "(local)"; $connectionInfo = array( "UID"=>"sa", "PWD"=>"PASS", "Database"=>"MARISTEST"); /* Connect using SQL Server Authentication. */ $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { echo "Unable to connect.</br>"; die( print_r( sqlsrv_errors(), true)); } $tsql = "SELECT * FROM users"; $stmt = sqlsrv_query( $conn, $tsql); if( $stmt === false ) { echo "Error in executing query.</br>"; die( print_r( sqlsrv_errors(), true)); } $data = "["; while($row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)) { $data = $data . json_encode($row) . ", "; } $data = $data . "]"; echo $data; /* Free statement and connection resources. */ sqlsrv_free_stmt( $stmt); sqlsrv_close( $conn); ?>
I have checked that remote connections are allowed for the server by right clicking on the instance name in SSMS, I then click on Properties and went to Connections. Allow Remote connections to this server is checked. Also I have installed the Native Driver for PHP. I am using the PHP Driver for Windows which was installed by the Web Platform Installer and confirmed in phpinfo() that sqlsrv was present. I have tried using (local), MARIS-IDX01/MARISIDX, ./MARISIDX, and localhost/MARISIDX. All yield the same result.
I have been scouring the internet looking for solutions but nothing has been able to help with my problem. Any ideas please???.
Thanks in advance