title: How can I install pdo_sqlsrv on my windows 2008 Server 2008 R2?
body: <p>I am trying to use PDO to connect to a SQL Server database. I have been struggling with it for a little bit now I get this Fatal error on my page where I am trying to connect to SQL Server</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IMSSP]: This extension requires the Microsoft SQL Server 2012 Native Client ODBC Driver to communicate with SQL Server. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: <a href="http://go.microsoft.com/fwlink/?LinkId=163712" rel="nofollow noreferrer">http://go.microsoft.com/fwlink/?LinkId=163712</a>'</p>
  </blockquote>
  
  <p>I have downloaded the drives from 
  <a href="http://www.microsoft.com/en-us/download/details.aspx?id=20098" rel="nofollow noreferrer">http://www.microsoft.com/en-us/download/details.aspx?id=20098</a> (SQLSRV30.EXE)
  I have placed those drivers in the ext directory where php is installed on the Server 2008 R2 server.</p>
  
  <p>I also have added these 2 lines at the end of the extension list in the php.ini file</p>
  
  <pre><code>extension=php_pdo_sqlsrv_53_nts.dll
  extension=php_sqlsrv_53_nts.dll
  </code></pre>
  
  <p>I am using PH PVersion 5.3.19
  Server API  CGI/FastCGI
  Thread Safety   disabled</p>
  
  <p>I do see <code>pdo_sqlsrv</code> but I don't see a Client API Version.</p>
  
  <p>What else do I need to do to be able to use PDO to connect to the remote server that has SQL databses?  Do I need to install anything on the remote servers?</p>
  
  <p>this is a screenshot of my php my admin section</p>
  
  <p><img src="https://i.stack.imgur.com/9RZWV.png" alt="enter image description here"></p>
  
  <p>This is my connection class</p>
  
  <pre><code>&lt;?php
  
  class connection {
  
      private $connString;
      private $userName;
      private $passCode;
      private $server;
      private $pdo;
      private $errorMessage;
      protected $lastQueryTime;
      protected $lastQuery;
  
      private $pdo_opt = array (
                              PDO::ATTR_ERRMODE            =&gt; PDO::ERRMODE_EXCEPTION,
                              PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_ASSOC,
                              PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET NAMES utf8"
                              );
  
  
  
  
      function __construct($dbName = DATABASE_NAME, $serverName = DATABASE_HOST){
  
          //sets credentials
          $this-&gt;setConnectionCredentials($dbName, $serverName);
  
          //start the connect
          $this-&gt;startConnection();
  
      }
  
      function startConnection(){
  
  
              $this-&gt;pdo = new PDO($this-&gt;connString, $this-&gt;userName, $this-&gt;passCode, $this-&gt;pdo_opt);
  
              if( ! $this-&gt;pdo){
  
                  $this-&gt;errorMessage  = 'Failed to connect to database. Please try to refresh this page in 1 minute. ';
                  $this-&gt;errorMessage .= 'However, if you continue to see this message please contact your system administrator.';
                  echo $this-&gt;getError();
              }
      }
  
  
      //this will close the PDO connection
      public function endConnection(){
  
          $this-&gt;pdo = null;
      }
  
      //return a dataset with the results
      public function getDataSet($query, $data = NULL)
      {
          $start = microtime(true);
          $cmd = $this-&gt;pdo-&gt;prepare( $query );
  
          $cmd-&gt;execute($data);
          $ret = $cmd-&gt;fetchAll();
          //$cmd-&gt;closeCursor();
          $this-&gt;lastQueryTime = microtime(true) - $start;
          $this-&gt;lastQuery = $query;
  
          return $ret;
      }
  
  
  
      public function processQuery($query, $data = NULL)
      {
          $start = microtime(true);
                 //$this-&gt;pdo-&gt;beginTransaction();
  
  
          $cmd = $this-&gt;pdo-&gt;prepare( $query );
          $ret = $cmd-&gt;execute($data);
                 //$this-&gt;pdo-&gt;commit();
                 //$cmd-&gt;closeCursor();
          $this-&gt;lastQueryTime = microtime(true) - $start;
          $this-&gt;lastQuery = $query;
  
          return $ret;
      }
  
  
      //return last insert id
      public function lastInsertId($name = NULL) {
          if(!$this-&gt;pdo) {
              return false;
          }
  
          return $this-&gt;pdo-&gt;lastInsertId($name);
      }
  
  
  
      public function getOneResult($query, $data = NULL){
          $cmd = $this-&gt;pdo-&gt;prepare( $query );
          $cmd-&gt;execute($data);
  
          return $cmd-&gt;fetchColumn();
      }
  
      public function getError(){
          if($this-&gt;errorMessage != '')
              return $this-&gt;errorMessage;
          else
              return true;  //no errors found
  
      }
  
      //this where you need to set new server credentials with a new case statment
      function setConnectionCredentials($dbName, $serv){
  
          switch($serv){
  
  
              //MS SQL server
              case 'SQLSERVER':
                  $this-&gt;connString   = 'sqlsrv:server='.$serv.';database='.$dbName;
                  $this-&gt;userName     = 'username';  
                  $this-&gt;passCode     = 'password';  
              break;
  
              //the defaults are predefined in the APP_configuration file - DO NOT CHANGE THE DEFAULT
              default:
                  $this-&gt;connString   = 'mysql:host='.DATABASE_HOST.';dbname='.DATABASE_NAME.';charset=utf8';
                  $this-&gt;userName     = DATABASE_USERNAME;
                  $this-&gt;passCode     = DATABASE_PASSWORD;
              break;
  
              }
  
      }
  
  
  public function lastQueryTime() {
      if(!$this-&gt;lastQueryTime) {
          throw new Exception('no query has been executed yet');
      }
      return $this-&gt;lastQueryTime;
  }
  
  public function lastQuery() {
      if(!$this-&gt;lastQuery) {
          throw new Exception('no query has been executed yet');
      }
      return $this-&gt;lastQuery;
  }
  
  
  
  }
  
  
  
  ?&gt;
  </code></pre>
  
  <p>This is how I use my class to pull a dataset</p>
  
  <pre><code>&lt;?php
  include('connection.php');
  
  $sql_db = new connection('databaseName','SQLSERVER');
  
  $call_details = $sql_db-&gt;getDataSet('SELECT
                                      LocalUserId AS loginName,
                                      RemoteNumberCallId AS PhoneNumber,
                                      SUM(CallDurationSeconds + HoldDurationSeconds + LineDurationSeconds) AS totalTalk
                                      FROM dbo.CallDetail WHERE LocalUserId = \'blah\' AND RemoteNumberCallId = \'123456789\'
                                      GROUP BY LocalUserId, RemoteNumberCallId');
  
  
  $call_details-&gt;endConnection();
  
  ?&gt;
  </code></pre>
  
  <p>I have even tried this code so I won't use my class and I still get the same error</p>
  
  <pre><code> $ss = new PDO("sqlsrv:server=SQLSERVER; Database=databaseName", "userName", "Password");
  </code></pre>