1

I am trying to connect to SQL Server using PHP PDO however it keeps giving me error. And, i already have file php_pdo_sqlsrv_53nts.dll in following directory xampp->php

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\xampp\htdocs\config.php:35 Stack trace: #0 C:\xampp\htdocs\config.php(35): PDO->__construct('sqlsrv:server=C...', 'username...', 'pass') #1 {main} thrown in C:\xampp\htdocs\config.php on line 35

Here is my PHP code:

<?php
      $serverName ="serverName";
            $dbName="databaseName";
            $username="userName";
            $password="passWrord";

            $connection = new PDO("sqlsrv:server=$serverName ; Database=$dbName",  "$username", "$password");

       if( $connection )
 {
     echo "Connection established.\n";
   }
else
  {
   echo "Connection could not be established.\n";
   die( print_r( sqlsrv_errors(), true));
  }



?>

Is there something wrong i am doing? Appreciated.

4

1 回答 1

1

我发现 xampp 和 wamp 使用 mssql 和 sqlite 驱动程序很痛苦,我发现最好的选择是在 Windows http://www.microsoft.com/web/platform/server.aspx中使用内置的 iis 服务器并下载驱动程序这里http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-mysql-for-php-applications-on-iis-7-and -以上

如果您不想移动到 iis,请确保 dll 文件已加载到 php.ini 文件中,请检查以下文件 extension=php_pdo_sqlsrv_53nts.dll 是否包含在您的 php.ini 文件中并且没有注释

于 2013-07-23T17:54:13.990 回答