title: Unable to connect SQL Server from PHP using Windows Authentication
body: <p>I'm trying to connect to MS-SQL Server from PHP-8.0 (hosting on IIS-10 localhost) using SQL Server Driver for PHP, i.e., SQLSRV-5.9. While connecting from a PHP page, if I use SQL Server Authentication, it's getting connected right away. But while using Windows Authentication, it's throwing an error in the browser saying:</p>
  <blockquote>
  <p>Connection could not be established.
  Array ( [0] =&gt; Array ( [0] =&gt; 28000 [SQLSTATE] =&gt; 28000 [1] =&gt; 18456
  [code] =&gt; 18456 [2] =&gt; [Microsoft][ODBC Driver 17 for SQL Server][SQL
  Server]Login failed for user 'NT AUTHORITY\IUSR'. [message] =&gt;
  [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for
  user 'NT AUTHORITY\IUSR'. ) [1] =&gt; Array ( [0] =&gt; 28000 [SQLSTATE] =&gt;
  28000 [1] =&gt; 18456 [code] =&gt; 18456 [2] =&gt; [Microsoft][ODBC Driver 17
  for SQL Server][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'.
  [message] =&gt; [Microsoft][ODBC Driver 17 for SQL Server][SQL
  Server]Login failed for user 'NT AUTHORITY\IUSR'. ) )</p>
  </blockquote>
  <p>My environment is Windows 10 Pro, Version 21H2, 64-bit. In my SQL Server, both Windows Authentication and SQL Server Authentication are enabled, and I'm able to connect to the server using both of them through SQL Server Management Studio. So what's stopping my PHP code to connect to the server using Windows Authentication? Both the PHP and SQL Sever are on the same PC. What am I doing wrong? As I'm new in PHP, can you please clarify it with a simple example?</p>
  <p>My connect-db.php code follows. Note how I used connection string for both Windows and SQL Server Authentication.</p>
  <pre><code>?php
      $serverName = &quot;(local)&quot;;    // Optionally use port number (1433 by default).
      $connectionString = array(&quot;Database&quot;=&gt;&quot;TestDB&quot;);    // Windows Authentication connection string.
      // $connectionString = array(&quot;UID&quot;=&gt;&quot;sa&quot;,&quot;PWD&quot;=&gt;&quot;sa&quot;,&quot;Database&quot;=&gt;&quot;TestDB&quot;);    // SQL Server Authentication connection string.
      $conn = sqlsrv_connect($serverName, $connectionString); // Connect to the server.
  
      if($conn === false) {
          echo &quot;Connection could not be established.&lt;br/&gt;&quot;;
          die(print_r(sqlsrv_errors(), true));
      } else {
          echo &quot;Connection established successfuly.&lt;br/&gt;&quot;;
      }
  
      sqlsrv_close($conn);    // Close connection resources.
  ?&gt;
  </code></pre>
  <p>Thanks and Regards!</p>