我已经在微软上下载了sqlsrv ...
并且在我的phpinfo()中:
在 C:\wamp\bin\apache\apache2.4.9\bin
和 C:\wamp\bin\php\php5.5.12
中的 php.ini
都启用了。
但仍然会得到以下错误。
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);