title: Connection failed to MSSQL in php
body: <p>I'm using SQL Server 2014 and I have this code to connect to my sql server : </p>
  
  <pre><code>&lt;?php 
  
  $serverName = "DESKTOP-P87SVPI\MSSQLSERVER";
  
  $connectionInfo = array("Database"=&gt;"map2");
  
  $conn = sqlsrv_connect($serverName,$connectionInfo);
  
  if ($conn){
  echo "finally";
  }
  else {
  print_r( sqlsrv_errors());
  
  }
  ?&gt;
  </code></pre>
  
  <p>I got this error  : </p>
  
  <blockquote>
    <p>Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 <a href="https://i.stack.imgur.com/pbrDF.png" rel="nofollow noreferrer">1</a> => 87
    [code] => 87 <a href="https://i.stack.imgur.com/q1KwG.png" rel="nofollow noreferrer">2</a> => [Microsoft][ODBC Driver 11 for SQL Server]SQL
    Server Network Interfaces: Connection string is not valid [87].
    [message] => [Microsoft][ODBC Driver 11 for SQL Server]SQL Server
    Network Interfaces: Connection string is not valid [87]. ) <a href="https://i.stack.imgur.com/pbrDF.png" rel="nofollow noreferrer">1</a> =>
    Array ( [0] => HYT00 [SQLSTATE] => HYT00 <a href="https://i.stack.imgur.com/pbrDF.png" rel="nofollow noreferrer">1</a> => 0 [code] => 0 <a href="https://i.stack.imgur.com/q1KwG.png" rel="nofollow noreferrer">2</a> =>
    [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
    [message] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout
    expired ) <a href="https://i.stack.imgur.com/q1KwG.png" rel="nofollow noreferrer">2</a> => Array ( [0] => 08001 [SQLSTATE] => 08001 <a href="https://i.stack.imgur.com/pbrDF.png" rel="nofollow noreferrer">1</a> => 87
    [code] => 87 <a href="https://i.stack.imgur.com/q1KwG.png" rel="nofollow noreferrer">2</a> => [Microsoft][ODBC Driver 11 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 11 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. ) )</p>
  </blockquote>
  
  <p>I checked this in MSSQL: </p>
  
  <pre><code>select @@servername + '\' + @@servicename
  </code></pre>
  
  <p>And it's the same :</p>
  
  <pre><code>DESKTOP-P87SVPI\MSSQLSERVER
  </code></pre>
  
  <p>And These are the drivers I have in phpInfo():
  <a href="https://i.stack.imgur.com/q1KwG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q1KwG.png" alt="enter image description here"></a></p>
  
  <p>Also I checked the remote connection in MSSQL and it's allowed.</p>
  
  <p>How to fix this ?</p>