此扩展需要SQL Server的Microsoft ODBC驱动程序11与SQL Server进行通信

Sto*_*rit 25 php sql-server

已经在microsoft上下载了sqlsrv ...

在此输入图像描述

和我的phpinfo()

在此输入图像描述

在此输入图像描述

启用了php.ini两个C:\wamp\bin\apache\apache2.4.9\binC:\wamp\bin\php\php5.5.12 在此输入图像描述

仍然有这样的错误.

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 
Run Code Online (Sandbox Code Playgroud)

我的代码是

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);
Run Code Online (Sandbox Code Playgroud)

Mar*_*ark 43

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

您可以在以下某个位置获取:

  • 值得注意的是,扩展列表中的**sqlserv**不是ODBC。这让我有点困惑。 (2认同)