PHP/PDO/SQL Server.未捕获的PDOException:找不到驱动程序 [英] PHP / PDO / SQL Server. Uncaught PDOException: could not find driver
问题描述
我有一个简单的脚本,可以在PHP 5.6中使用,但不能在PHP 7.0中使用:
I have a simple script which works in PHP 5.6 but does not work in PHP 7.0:
$conn = new PDO("sqlsrv:Server=10.6.2.105;Database=mydb", "myuname", "mypwd");
$sql = "SELECT TOP 3 txt FROM mytab";
foreach ($conn->query($sql) as $row)
print $row["txt"] . "\r\n";
在PHP 7.0中运行它时,出现以下错误:
When I run it in PHP 7.0, I get the following error:
Uncaught PDOException: could not find driver
根据 http://php.net/manual/en/pdo.installation .php 对于Windows安装,我不需要5.3以上版本的php.ini文件中的extension = php_pdo.dll.
According to http://php.net/manual/en/pdo.installation.php I don't need extension=php_pdo.dll in my php.ini file in versions above 5.3 for windows installs.
我确实有以下内容:
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
extension=php_pdo_sqlite.dll
此外,我可以直接使用sql server,而不能与PDO一起使用.
Also, I can use sql server directly, just not with PDO.
我还需要什么才能使它正常工作?我在哪里找到驱动程序?
What else do I need to get this working? Where do I find the driver for this?
详细信息:
PHP 7.0.5
Windows 8.1
NTS x86
推荐答案
已经下载了驱动程序,但无法正常工作.找到了新的驱动程序站点,这个站点可以正常工作.
Had already downloaded the driver and it didn't work. Found a new site for the driver and this one works.
https://github.com/Microsoft/msphpsql/releases
添加了php.ini行:
php.ini line added:
extension=php_pdo_sqlsrv_7_nts.dll
这篇关于PHP/PDO/SQL Server.未捕获的PDOException:找不到驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!