I'm trying use PHP to establish a connection to a SQL server
I can access the server remotely using SQL Server Management studio.
Then if i run:
select @@servername + '\' + @@servicename
I get:
Server_Name\Instance_Name
(maybe it's worth noting that i can't use this Server_Name to connect to the server in Management Studio - I have to use the public IP instead, not sure why, but i am noob so maybe that's normal?)
The PHP script i am running (On the same machine i am using to establish the Management Studio Connection) looks like this:
<?php
$username = "same_user_as_for_management_studio";
$password = "same_pass_as_for_management_studio";
$serverName = "Server_Name\Instance_Name";
$db = "Example";
$connectionInfo = array( "Database"=> $db, "UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
I have tried substituting the server name for the public IP but still no joy. The error i get is:
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 87 [code] => 87 [2] => [Microsoft][SQL Server Native Client 11.0]SQL Server Network Interfaces: Connection string is not valid [87]. [message] => [Microsoft][SQL Server Native Client 11.0]SQL Server Network Interfaces: Connection string is not valid [87]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired [message] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 87 [code] => 87 [2] => [Microsoft][SQL Server Native Client 11.0]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][SQL Server Native Client 11.0]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. ) )