php 此扩展需要 Microsoft ODBC Driver 11 for SQL Server 才能与 SQL Server 通信

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34401170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:57:26  来源:igfitidea点击:

This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server

phpsql-server

提问by Storm Spirit

ALready downloaded the sqlsrv on microsoft...

已经在微软下载了 sqlsrv...

enter image description here

在此处输入图片说明

and on my phpinfo()

在我的 phpinfo() 上

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enabled on php.inion both C:\wamp\bin\apache\apache2.4.9\binand C:\wamp\bin\php\php5.5.12enter image description here

启用了php.ini两个C:\wamp\bin\apache\apache2.4.9\binC:\wamp\bin\php\php5.5.12在此处输入图片说明

and still got error like this.

仍然有这样的错误。

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 

and my code is

我的代码是

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);

回答by Mark

Apart of the pdo_sqlsrvextension, you also need to have the ODBC 11 driver installed on your machine.

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

You can get it at one of these locations:

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