简体   繁体   English

将 PDO SQLSRV 与 PHP 一起使用不起作用

[英]Using PDO SQLSRV with PHP not working

I have been trying to get the PDO SQLSRV to work (in a windows server 2012 R2) for a while now and have found instructions on how I'm supposed to set it up so that the drivers load on starting up PHP, but it's not working.我一直在试图让PDO SQLSRV工作(在Windows Server 2012中R2),而现在,发现说明书上,我应该如何设置它,这样在启动PHP驱动程序载入,但它不是在职的。

I have located the correct php.ini file (and tested by commenting out some of the other PDO drivers to make sure).我找到了正确的 php.ini 文件(并通过注释掉其他一些 PDO 驱动程序进行测试以确保)。 I added the appropriate line at the end of the [ExtensionList] like this:我在[ExtensionList]的末尾添加了适当的行,如下所示:

extension=php_pdo_sqlsrv_7_ts_x64.dll

I added several of those, but nothing is working.我添加了其中的几个,但没有任何效果。 I check it by running a script with phpinfo() to show me what is going on.我通过使用phpinfo()运行脚本来检查它,以显示发生了什么。 The extension list looks like this:扩展列表如下所示:

[ExtensionList]
; extension=php_mysqli.dll
extension=php_mbstring.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_curl.dll
extension=php_exif.dll
extension=php_xmlrpc.dll
extension=php_openssl.dll
extension=php_soap.dll
extension=php_pdo_mysql.dll
; extension=php_pdo_sqlite.dll
extension=php_imap.dll
extension=php_tidy.dll
extension=php_pdo_sqlsrv_7_ts_x64.dll
extension=php_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_nts_x64.dll
extension=php_sqlsrv_7_nts_x64.dll
extension=php_pdo_sqlsrv_72_ts_x64.dll
extension=php_sqlsrv_72_ts_x64.dll
extension=php_pdo_sqlsrv_72_nts_x64.dll
extension=php_sqlsrv_72_nts_x64.dll
extension=php_pdo_sqlsrv_72_ts.dll
extension=php_sqlsrv_72_ts.dll

So under PDO should be mysql and sqlsrv , but I only see the mysql .所以PDO下应该是mysqlsqlsrv ,但是我只看到了mysql

在此处输入图片说明

Am I missing something?我错过了什么吗?

Update更新

I tried updating the php.ini file so that it has the full path for those extensions, still didn't make any difference.我尝试更新 php.ini 文件,使其具有这些扩展的完整路径,但仍然没有任何区别。

Architecture=x64, Thread Safety=disabled, PHP Version=7.2.2, Microsoft ODBC Driver 17 for SQL Server Architecture=x64, Thread Safety=disabled, PHP Version=7.2.2, Microsoft ODBC Driver 17 for SQL Server

Update II更新二

I have tried removing all references except the 2 that I need and gave them fully qualified directory paths:我已尝试删除除我需要的 2 个之外的所有引用,并为它们提供了完全限定的目录路径:

[ExtensionList]
; extension=php_mysqli.dll
extension=php_mbstring.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_curl.dll
extension=php_exif.dll
extension=php_xmlrpc.dll
extension=php_openssl.dll
extension=php_soap.dll
; extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension="C:\Program Files\PHP\v7.2\ext\php_pdo_sqlsrv_72_nts_x64.dll"
extension="C:\Program Files\PHP\v7.2\ext\php_pdo_sqlsrv_7_nts_x64.dll"
extension=php_pdo_sqlsrv.dll
extension=php_imap.dll
extension=php_tidy.dll

I am still unable to get SQL SRV to work, it still does not show up in the PHPInfo print out.我仍然无法让 SQL SRV 工作,它仍然没有显示在 PHPInfo 打印输出中。

Are there any other suggestions of what I can try?还有其他关于我可以尝试的建议吗?

UPDATE更新

Yesterday I reinstalled PHP 7.2 (now version 7.2.6) from here .昨天我从这里重新安装了 PHP 7.2(现在是 7.2.6 版)。 And reinstalled the Microsoft Drivers 5.2 for PHP for SQL Server from here .并从此处重新安装 Microsoft Drivers 5.2 for PHP for SQL Server。 And updated my php.ini file like this:并像这样更新我的 php.ini 文件:

[ExtensionList]
extension=php_mbstring.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_curl.dll
extension=php_exif.dll
extension=php_xmlrpc.dll
extension=php_openssl.dll
extension=php_soap.dll
extension=php_imap.dll
extension=php_tidy.dll
extension=php_pdo_sqlsrv.dll
extension="C:\Program Files\PHP\v7.2\ext\php_pdo_sqlite.dll"
; extension=php_pdo_mysql.dll
extension=php_mysqli.dll

To see if that would help or make any difference.看看这是否会有所帮助或有所作为。 The php_pdo_sqlsrv.dll still does not load, then php_pdo_sqlite.dll did load, and they are both in the same folder as the php_mysqli.dll which also loaded. php_pdo_sqlsrv.dll仍然没有加载,然后php_pdo_sqlite.dll确实加载了,并且它们都与同样加载的 php_mysqli.dll 位于同一文件夹中。 I have followed the instructions that I found here and nothing seems to be working to get that SQL SRV dll to load.我已按照我在此处找到的说明进行操作,但似乎没有任何方法可以加载该 SQL SRV dll。

I was finally able to figure it out and get it working.我终于能够弄清楚并让它工作。 I tried to install CakePHP which requires Composer.我尝试安装需要 Composer 的 CakePHP。 So while installing Composer I got an error that I had not seen before and posted a question about that.因此,在安装 Composer 时,我遇到了一个我以前从未见过的错误,并发布了一个关于此的问题。 The end result is that I had to reinstall PHP again clean and then update the php.ini so only have the TS versions of PDO SQLSRV.最终结果是我不得不再次重新安装 PHP,然后更新 php.ini 以便只有 PDO SQLSRV 的 TS 版本。

The other question is here另一个问题在这里

如果有人偶然发现了这一点,如果您不取消注释 php.ini 中的 ext dir conf 它将不会加载模块,这看起来很简单,但很多人(包括我)注意到了,我希望 PHP 会寻找它的默认目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM