此扩展需要 Microsoft ODBC 驱动程序 11 for SQL Server 才能与 SQL Server 通信

2022-08-30 13:54:27

ALready在microsoft上下载了sqlsrv...

enter image description here

和我的 phpinfo()

enter image description here

enter image description here

在 和 上启用php.iniC:\wamp\bin\apache\apache2.4.9\binC:\wamp\bin\php\php5.5.12 enter image description here

并且仍然遇到这样的错误。

Failed to get DB handle: SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 

我的代码是

try {
    $dbh = new PDO ("sqlsrv:Server=$host;Database=$db","$user","$pass");
  } catch (PDOException $e) {
    echo "Failed to get DB handle: " . $e->getMessage() . "\n";
    exit;
  }
  $stmt = $dbh->prepare("select top 5 from teams");
  $stmt->execute();
  while ($row = $stmt->fetch()) {
    print_r($row);
  }
  unset($dbh); unset($stmt);

答案 1

除了扩展之外,您还需要在计算机上安装 ODBC 11 驱动程序。pdo_sqlsrv

您可以在以下位置之一获取它:


答案 2

推荐