title: Connecting to an SQL Server Database with PHP
body: <p>I'm trying to connect to a Microsoft SQL Server 2008 R2 database using a PHP application in NetBeans 8.0.1. I have installed XAMP 1.8.2 and PHP 5.4.31 on Windows XP. The Apache server is setup properly and I can reach the XAMPP config page here: <a href="http://localhost:1337/index.php" rel="nofollow">http://localhost:1337/index.php</a>. </p>
  
  <p>I have correctly configured the Microsoft SQL Server Driver (SQLSRV) for PHP...I downloaded the following files:
      php_sqlsrv_54_ts.dll
      php_pdo_sqlsrv_54_ts.dll
  I added the extensions to the php.ini file and restarted the Apache service.</p>
  
  <p>I have a SQL Server named: INTERACT-21292F\SQLEXPRESS (name found in properties of SQL Server Management Studio) and SQLExpress service is listening on port 1433...Here is my index.php file:</p>
  
  <pre><code>&lt;?php
  
  
          $serverName = "INTERACT-21292F\SQLEXPRESS, 1433";
  
  
          $connectionInfo = array("Database" =&gt; "GDMediaDB", "UID" =&gt; "blah", "PWD" =&gt; "blah");
  
  
          $conn = sqlsrv_connect($serverName, $connectionInfo);
  
  
          if (!$conn) {
              echo("Something went wrong while connecting to MSSQL");
          } else {
              echo "Connection Established";
          }
  
      ?&gt;
  </code></pre>
  
  <p>output: Something went wrong while connecting to MSSQL.</p>
  
  <p>I am unable to make a connection to the database...Why is this happening?</p>
  
  <p><strong>EDIT: Result of var_dump(sqlsrv_errors()):</strong></p>
  
  <pre><code>array (size=2)
    0 =&gt; 
      array (size=6)
        0 =&gt; string 'IMSSP' (length=5)
        'SQLSTATE' =&gt; string 'IMSSP' (length=5)
        1 =&gt; int -49
        'code' =&gt; int -49
        2 =&gt; string 'This extension requires the ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712' (length=184)
        'message' =&gt; string 'This extension requires the ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712' (length=184)
    1 =&gt; 
      array (size=6)
        0 =&gt; string 'IM002' (length=5)
        'SQLSTATE' =&gt; string 'IM002' (length=5)
        1 =&gt; int 0
        'code' =&gt; int 0
        2 =&gt; string '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified' (length=91)
        'message' =&gt; string '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified' (length=91)
  </code></pre>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>I've installed the correct version of XAMPP(v. 1.6.4 comes with PHP 5.2.4 which is compatible with Windows XP). The problem now is that the SQL Server driver extensions fail to load. I simply download the drivers and place them in the xampp/php/ext/ folder and update the php.ini file to include:</p>
  
  <pre><code>extension=php_pdo_sqlsrv_52_ts_vc6.dll
  extension=php_sqlsrv_52_ts_vc6.dll
  </code></pre>
  
  <p>When I open <a href="http://localhost:1337/" rel="nofollow">http://localhost:1337/</a> and run phpInfo() the sqlsrv extensions do not show up...</p>
  
  <p>How do I correctly install SQL Server drivers for PHP 5.2.4?</p>