php PDO MSSQL Server - 未找到驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11246007/
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
PDO MSSQL Server - Driver not found
提问by Richard
I am currently trying to connect to my localdb on MSSQL 2012 Express.
我目前正在尝试在 MSSQL 2012 Express 上连接到我的 localdb。
I have downloaded and installed the official microsoft driver from http://www.microsoft.com/en-us/download/details.aspx?id=20098
我已经从http://www.microsoft.com/en-us/download/details.aspx?id=20098下载并安装了官方的 microsoft 驱动程序
I get some kind of SQLSRV section in my phpinfo(). But when I try to create a new PDO object it says it does not have the driver. Which I could understand since it is not mentioned on the phpinfo() PDO section, but it has its own section + the get_loaded_extensions also shows sqlsrv. I suppose thats from the official MS Driver ? I am using the php_sqlsrv_53_nts.dll With my Zend Server CE 5.6 with PHP 5.3.9
我在我的 phpinfo() 中得到了某种 SQLSRV 部分。但是当我尝试创建一个新的 PDO 对象时,它说它没有驱动程序。我可以理解,因为 phpinfo() PDO 部分没有提到它,但它有自己的部分 + get_loaded_extensions 也显示 sqlsrv。我想那是来自官方的 MS Driver 吗?我正在使用 php_sqlsrv_53_nts.dll 和我的 Zend Server CE 5.6 和 PHP 5.3.9
Now as far as I understood I downloaded the wrong driver and should try the one that is brought by the PECL manager? There is only the sourcecode available and obviously I am on a windows machine so I can forget about everything that I need to compile myself - I am actually getting the suffix errors when using the powershell and my pecl / pear installation.
现在据我所知我下载了错误的驱动程序,应该尝试PECL管理器带来的驱动程序吗?只有源代码可用,显然我在 Windows 机器上,所以我可以忘记我需要自己编译的所有内容 - 在使用 powershell 和我的 pecl / pear 安装时,我实际上遇到了后缀错误。
Has anybody solve that problem ? Any help much appreciated
有没有人解决这个问题?非常感谢任何帮助
All the best, Richard
一切顺利,理查德
采纳答案by Richard
Alright. I suppose its just one of these days.
好吧。我想这只是这些日子之一。
I got the wrong extension loaded from the supplied ones by MS. I needed to use php_pdo_sqlsrv_53_ntsrather than
php_sqlsrv_53_nts
我从 MS 提供的扩展中加载了错误的扩展。我需要使用php_pdo_sqlsrv_53_nts而不是
php_sqlsrv_53_nts
Thanks for all the help
感谢所有的帮助
回答by Martin Müller
The PDO Extension is not the same as the native driver Microsoft is offering. For PDO you must enable
PDO 扩展与 Microsoft 提供的本机驱动程序不同。对于 PDO,您必须启用
extension=php_pdo_mssql.dll
in your php.ini.
在你的 php.ini 中。
Normally this file (php_pdo_mssql.dll) should be in your PHP extension-directory (C:...\php\ext). If it's not there you can download PHP from http://windows.php.net/download/and just take the extension from a package there (take one that correspond with your PHP version of course).
通常这个文件 (php_pdo_mssql.dll) 应该在你的 PHP 扩展目录 (C:...\php\ext) 中。如果它不存在,您可以从http://windows.php.net/download/下载 PHP,然后从那里的软件包中获取扩展名(当然,获取与您的 PHP 版本相对应的扩展名)。
//edit: just read you latest comment. This extension is available for a very long time now and can be considered working. If you are not allowed to use it you must rewrite your code to use the functions the native driver offers for PHP.
//编辑:刚刚阅读您的最新评论。这个扩展现在可以使用很长时间了,可以被认为是有效的。如果不允许使用它,则必须重写代码以使用本机驱动程序为 PHP 提供的功能。
回答by Levite
Another possibility is to use the odbc drivers which are by default included in the php extensions, you still might have to uncomment them in your php.inithough.
另一种可能性是使用默认情况下包含在 php 扩展中的 odbc 驱动程序,您仍然可能需要在您的文件中取消对它们的注释php.ini。
extension=php_pdo_odbc.dll
Don't forget to restart your server afterwards ;-)
之后不要忘记重新启动服务器;-)
And then use it like this:
然后像这样使用它:
$db = new PDO('odbc:Driver={SQL Server};Server=192.168.x.x;Database=DatabaseName; Uid=User;Pwd=Password');
$stmt = $db->query("SELECT the_usual FROM aTable WHERE all='well'");

