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
This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server
提问by Storm Spirit
ALready downloaded the sqlsrv on microsoft...
已经在微软下载了 sqlsrv...
and on my phpinfo()
在我的 phpinfo() 上
enabled on php.ini
on both C:\wamp\bin\apache\apache2.4.9\bin
and C:\wamp\bin\php\php5.5.12
启用了php.ini
两个C:\wamp\bin\apache\apache2.4.9\bin
和C:\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_sqlsrv
extension, 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:
您可以在以下位置之一获取它: