php MSSQL PDO 找不到驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16310892/
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 10:54:36  来源:igfitidea点击:

MSSQL PDO could not find driver

phpdatabasepdo

提问by

I'm using PHP Version 5.3.8 that was installed via XAMPP along with Microsoft SQL Server 2008 R2 (SQLEXPRESS). I have the drivers installed correctly (i guess) and have added the correct line into php.ini (extension=php_pdo_sqlsrv_53_ts_vc9.dll to be exact).

我正在使用通过 XAMPP 和 Microsoft SQL Server 2008 R2 (SQLEXPRESS) 安装的 PHP 版本 5.3.8。我已经正确安装了驱动程序(我猜)并在 php.ini 中添加了正确的行(确切地说是 extension=php_pdo_sqlsrv_53_ts_vc9.dll)。

I'm trying to connect to the server like so:

我正在尝试像这样连接到服务器:

try {

    $DBH = new PDO("mssql:host=xxxx;dbname=xxxx", 'xxxx', 'xxxx');

} catch(PDOException $e) {

    echo $e->getMessage();
}

I get the "could not find driver" error, and I've tweaked it all kinds of ways to solve the problem. I've tried all other kinds of drivers, but this is the only one that Apache doesn't give me an error on startup. When I run phpinfo(), the pdo_sqlsrv fields are all blank except pdo_sqlsrv.log_severity which is set to 0.

我收到“找不到驱动程序”的错误消息,我已经用各种方法来解决这个问题。我已经尝试了所有其他类型的驱动程序,但这是 Apache 在启动时不给我错误的唯一一个。当我运行 phpinfo() 时,除了 pdo_sqlsrv.log_severity 设置为 0 之外,pdo_sqlsrv 字段都是空白的。

I DL'd my drivers from microsoft, and I've tried both 2.0 and 3.0

我从微软下载了我的驱动程序,我已经尝试了 2.0 和 3.0

Any advice would be awesome!!

任何建议都会很棒!!

采纳答案by Ivo

mssqlis the old way of doing it, sqlsrvshould be more appropriate! In fact the extension is called (extension=php_pdo_sqlsrv_53_ts_vc9.dll) as well ;)

mssql是老办法了,sqlsrv应该比较合适吧!事实上,扩展名也被称为 (extension=php_pdo_ sqlsrv_53_ts_vc9.dll) ;)

try {

    $DBH = new PDO("sqlsrv:Server=xxxx;Database=xxxx", 'xxxx', 'xxxx');

} catch (PDOException $e) {

    echo $e->getMessage();
}

Hope this helps!

希望这可以帮助!

Source : http://php.net/manual/fr/ref.pdo-sqlsrv.connection.php

来源:http: //php.net/manual/fr/ref.pdo-sqlsrv.connection.php

examples from documentation

文档中的示例

回答by James

Not sure if this is due to running a CentOS x86_64 machine but sqlsrvdidn't work as the driver for me, I had to use dblib:

不确定这是否是由于运行 CentOS x86_64 机器但sqlsrv不能作为我的驱动程序,我不得不使用dblib

try {

    $DBH = new PDO("dblib:host=xxxx;dbname=xxxx", 'xxxx', 'xxxx');

} catch (PDOException $e) {

    echo $e->getMessage();
}

Source and thanks to.

来源并感谢.