IIS上的MSSQL和PHP 5.3.5之间的连接不起作用 [英] Connection between MSSQL and PHP 5.3.5 on IIS is not working

查看:135
本文介绍了IIS上的MSSQL和PHP 5.3.5之间的连接不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近安装了IIS,PHP 5.3.5和MySQL,并且一切正常。



然后我还要求MS SQL以及我认为这将是一个容易的任务,现在让我疯狂,我无法弄清楚如何使它工作。



根据 php_info ) MS SQL驱动程序未加载。



我下载了 php_mssql.dll 并在 php.ini 中启用它,但它没有起作用。我发现新版本的PHP使用不同的DLL。所以我下载了新的,把它放在ext文件夹中,更新了 php.ini ,但还是没有运气。



php_info()仍然没有显示驱动程序加载。



我即将卸载IIS和PHP,然后安装我之前安装的Apache。



这个问题是我最后一次尝试,任何人都可以帮忙?

解决方案

这是一个客户的代码段常见问题我之前写了一篇文章,以帮助我们的专用主机客户使用MS SQL驱动程序来获取PHP并运行。它可能会复制上述评论中已经传授的一些知识,但完整性也可以帮助别人从头开始:



注意:显然,PHP版本号已经移动了一点,因为我写了这个,但一般原则仍然适用。






必需:
SQL Server的Microsoft驱动程序需要SQL Native Client:


Microsoft SQL Server 2008 R2 Native Client X64 - 适用于64位Windows



Microsoft SQL Server 2008 R2 Native客户端X32 - 用于32位Windows


下载并安装与您的系统相匹配的Native Client驱动程序。

PHP MS SQL驱动器rs:



下载适用于SQL Server的PHP的Microsoft驱动程序:


Microsoft驱动程序对于SQL Server的PHP


该文件是一个自解压缩的可执行文件,所以只需使用7zip或WinRAR并提取文件到你选择的文件夹。我们现在需要决定选择哪个驱动程序来匹配您的PHP安装。



PHP 5.3.5有四种不同的口味:




  • PHP 5.3.5非线程安全VC9

  • PHP 5.3.5非线程安全VC6

  • PHP 5.3.5 Threadsafe VC9

  • PHP 5.3.5 Threadsafe VC6



告诉哪个版本您已经安装了 snapshot.txt 文件,该文件与 php.exe php-cgi.exe 等不要使用notepad.exe,因为文件只使用换行符( \\\
)在开始时,结束(unix格式)和记事本将它们转换为单行。



在文件中,您将看到一行(在第6行附近,第1行你确实使用了记事本)开头: Build:

 
Build :D:\php-sdk\snap_5_3\vc9\x86\obj\Release - 非线程安全,VC9构建
构建:D:\php -sdk\snap_5_3\vc6\x86\obj\Release - 非线程安全,VC6构建
构建: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

这将告诉我们您正在运行什么版本的PHP。



从您提取MS SQL PHP驱动程序的文件夹中,选择与正在使用的PHP版本相匹配的驱动程序(如果您不使用PDO,则不需要复制 php_pdo _ 驱动程序):

 
PHP 5.3.5非线程安全VC9:php_sqlsrv_53_nts_vc9.dll,php_pdo_sqlsrv_53_nts_vc9.dll
PHP 5.3.5非线程安全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

假设您的PHP安装位于 C:\PHP 中,将这些文件复制(不要移动)到您的 C:\PHP\EXT 文件夹。



打开 C:\PHP \PHP.INI ,并找到文件的动态扩展程序部分,然后添加:

 
extension = php_sqlsrv_53_nts_vc9.dll
extension = php_pdo_sqlsrv_53_nts_vc9.dll< - 可选

最后,为了确保PHP可以找到这些扩展名,请确保中的 extension_dir 指令C:\PHP\PHP.INI 设置为 C:\PHP\EXT

 
extension_dir = C:\PHP\ext

重新启动IIS并调用 phpinfo()。如果一切顺利,您应该会看到:





如果您还加载了PDO驱动程序,您应该看到:




I recently installed IIS, PHP 5.3.5 and MySQL, and had it all working.

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.

According to php_info() the MS SQL drivers aren't loading.

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_info() still isn't showing the drivers are loaded.

I am about to uninstall IIS and PHP, and install Apache, which I've installed before.

This question is my last attempt, can anyone help?

解决方案

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:

Note: Clearly the PHP version numbers have moved on a bit since I wrote this but the general principles still apply.


Installation Pre-requisite: The SQL Native Client is required for the Microsoft Drivers for PHP for SQL Server:

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

Download and install the Native Client driver that matches your system.

PHP MS SQL Drivers:

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.

PHP 5.3.5 comes in four different flavours:

  • 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

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.

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::

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.

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):

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.

Open C:\PHP\PHP.INI and locate the Dynamic Extensions part of the file and add:

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:

extension_dir = C:\PHP\ext

Restart IIS and call phpinfo(). If all is well you should see:

And if you also loaded the PDO driver you should see:

这篇关于IIS上的MSSQL和PHP 5.3.5之间的连接不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆