IIS 上的 MSSQL 和 PHP 5.3.5 之间的连接不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5425322/
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
Connection between MSSQL and PHP 5.3.5 on IIS is not working
提问by Naner
I recently installed IIS, PHP 5.3.5 and MySQL, and had it all working.
我最近安装了 IIS、PHP 5.3.5 和 MySQL,并且一切正常。
I then has a requirement for MS SQL as well, and what I thought would be an easy task, is now driving me crazy and I can't figure out how to make it work.
然后我也需要 MS SQL,我认为这是一项简单的任务,现在让我发疯,我无法弄清楚如何使它工作。
According to php_info()
the MS SQL drivers aren't loading.
根据php_info()
MS SQL 驱动程序未加载。
I downloaded php_mssql.dll
and enabled it in php.ini
but it didn't work. I found out that the new version of PHP uses a different dll. So I downloaded the new one, put that in the ext folder, and updated the php.ini
, but still no luck.
我下载php_mssql.dll
并启用它,php.ini
但它不起作用。我发现新版本的 PHP 使用了不同的 dll。所以我下载了新的,把它放在 ext 文件夹中,并更新了php.ini
,但仍然没有运气。
php_info()
still isn't showing the drivers are loaded.
php_info()
仍然没有显示驱动程序已加载。
I am about to uninstall IIS and PHP, and install Apache, which I've installed before.
我即将卸载 IIS 和 PHP,然后安装我之前安装过的 Apache。
This question is my last attempt, can anyone help?
这个问题是我最后一次尝试,有人可以帮忙吗?
回答by Kev
This is a snippet from a customer FAQ I wrote up a wee while ago to help our dedicated hosting customers get PHP up and running with the MS SQL Drivers. It may duplicate some knowledge already imparted in the comments above, but it's completeness may also help others starting from scratch:
这是我不久前写的客户常见问题解答的片段,以帮助我们的专用托管客户使用 MS SQL 驱动程序启动和运行 PHP。它可能会复制上面评论中已经传授的一些知识,但它的完整性也可能有助于其他人从头开始:
Note:Clearly the PHP version numbers have moved on a bit since I wrote this but the general principles still apply.
注意:很明显,自从我写这篇文章以来,PHP 版本号已经发生了一些变化,但一般原则仍然适用。
Installation Pre-requisite:The SQL Native Client is required for the Microsoft Drivers for PHP for SQL Server:
安装先决条件:Microsoft Drivers for PHP for SQL Server 需要 SQL Native Client:
Microsoft SQL Server 2008 R2 Native Client X64 - for 64 bit Windows
or
Microsoft SQL Server 2008 R2 Native Client X32 - for 32 bit Windows
Microsoft SQL Server 2008 R2 Native Client X64 - 适用于 64 位 Windows
或
Microsoft SQL Server 2008 R2 Native Client X32 - 适用于 32 位 Windows
Download and install the Native Client driver that matches your system.
下载并安装与您的系统匹配的 Native Client 驱动程序。
PHP MS SQL Drivers:
PHP MS SQL 驱动程序:
Download the Microsoft Drivers for PHP for SQL Server:
下载 Microsoft Drivers for PHP for SQL Server:
The file is a self-extracting executable so just use 7zip or WinRAR and extract the files to a folder of your choice. We now need to decide which driver to choose that matches your PHP installation.
该文件是一个自解压可执行文件,因此只需使用 7zip 或 WinRAR 并将文件解压缩到您选择的文件夹中。我们现在需要决定选择与您的 PHP 安装相匹配的驱动程序。
PHP 5.3.5 comes in four different flavours:
PHP 5.3.5 有四种不同的风格:
- PHP 5.3.5 Non-threadsafe VC9
- PHP 5.3.5 Non-threadsafe VC6
- PHP 5.3.5 Threadsafe VC9
- PHP 5.3.5 Threadsafe VC6
- PHP 5.3.5 非线程安全 VC9
- PHP 5.3.5 非线程安全 VC6
- PHP 5.3.5 线程安全 VC9
- PHP 5.3.5 线程安全 VC6
To tell which version you have installed open the snapshot.txt
file which lives in the same folder as php.exe
, php-cgi.exe
etc. Don't use notepad.exe because the file uses just line feed (\n
) for line ends (unix format) at the start and notepad mangles these into a single line.
告诉你已经安装了该版本中打开snapshot.txt
它生活在同一文件夹中的文件php.exe
,php-cgi.exe
等等。不要因为的notepad.exe文件只使用换行(使用\n
)线路端(UNIX格式)开始和记事本轧液这些成一行。
In the file you will see a line (around line 6, or near the middle of line 1 of you did use notepad) starting with: Build:
:
在文件中,您将看到一行(在第 6 行附近,或在您使用记事本的第 1 行中间附近)以以下开头Build:
:
Build: D:\php-sdk\snap_5_3\vc9\x86\obj\Release - non-threadsafe, VC9 build Build: D:\php-sdk\snap_5_3\vc6\x86\obj\Release - non-threadsafe, VC6 build Build: D:\php-sdk\snap_5_3\vc9\x86\obj\Release_TS - threadsafe, VC9 build Build: D:\php-sdk\snap_5_3\vc6\x86\obj\Release_TS - threadsafe, VC6 build
This tells us what version of PHP you're running.
这告诉我们您正在运行的 PHP 版本。
From the folder you extracted the MS SQL PHP drivers, choose the driver(s) that matches the version of PHP being used (if you're not using PDO then you don't need to copy the php_pdo_
drivers):
从您提取 MS SQL PHP 驱动程序的文件夹中,选择与正在使用的 PHP 版本匹配的驱动程序(如果您不使用 PDO,则不需要复制php_pdo_
驱动程序):
PHP 5.3.5 Non-threadsafe VC9: php_sqlsrv_53_nts_vc9.dll, php_pdo_sqlsrv_53_nts_vc9.dll PHP 5.3.5 Non-threadsafe VC6: php_sqlsrv_53_nts_vc6.dll, php_pdo_sqlsrv_53_nts_vc6.dll PHP 5.3.5 Threadsafe VC9: php_sqlsrv_53_ts_vc9.dll, php_pdo_sqlsrv_53_ts_vc9.dll PHP 5.3.5 Threadsafe VC6: php_sqlsrv_53_ts_vc6.dll, php_pdo_sqlsrv_53_ts_vc6.dll
Assuming your PHP installation lives in C:\PHP
, copy (DON'T MOVE) these files to your C:\PHP\EXT
folder.
假设您的 PHP 安装位于 中C:\PHP
,请将这些文件复制(不要移动)到您的C:\PHP\EXT
文件夹中。
Open C:\PHP\PHP.INI
and locate the Dynamic Extensions
part of the file and add:
打开C:\PHP\PHP.INI
并找到Dynamic Extensions
文件的一部分并添加:
extension=php_sqlsrv_53_nts_vc9.dll extension=php_pdo_sqlsrv_53_nts_vc9.dll <-- optional
Finally, to be sure that PHP can find these extensions, ensure the extension_dir
directive in C:\PHP\PHP.INI
is set to C:\PHP\EXT
:
最后,为了确保 PHP 可以找到这些扩展,请确保将extension_dir
指令 inC:\PHP\PHP.INI
设置为C:\PHP\EXT
:
extension_dir = C:\PHP\ext
Restart IIS and call phpinfo()
. If all is well you should see:
重新启动 IIS 并调用phpinfo()
. 如果一切顺利,您应该看到:
And if you also loaded the PDO driver you should see:
如果您还加载了 PDO 驱动程序,您应该看到:
回答by Raunak
The above mentioned:
以上提及的:
extension=php_sqlsrv_53_nts_vc9.dll
extension=php_pdo_sqlsrv_53_nts_vc9.dll
扩展名=php_sqlsrv_53_nts_vc9.dll
扩展名=php_pdo_sqlsrv_53_nts_vc9.dll
what I found is incorrect.
我发现的是不正确的。
Therefore, it is likely to be:
因此,很可能是:
extension=php_sqlsrv_53_ts_vc9.dll
extension=php_pdo_sqlsrv_53_ts_vc9.dll