PHP 5.3无法识别Native Client连接到MS SQL [英] PHP 5.3 not recognizing Native Client to connect to MS SQL

查看:68
本文介绍了PHP 5.3无法识别Native Client连接到MS SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一台运行在

Windows Server 2003 32位IIS6.0(我们有一些使用32位组件的经典ASP应用程序,因此我们无法升级到2008 64位)

Windows Server 2003 32 Bit IIS6.0 (We have some Classic ASP apps that uses 32bit components so we can't upgrade to 2008 64bit)

我们的数据库服务器在运行的另一台计算机上 Windows Server 2008 64位 MS SQL 2008 R2 64位

Our DB Server is on a separate computer running Windows Server 2008 64 Bit MS SQL 2008 R2 64 Bit

我已经安装了以下版本的PHP PHP 5.3.10 建立日期2012年2月2日20:26:31 编译器MSVC9(Visual C ++ 2008)

I have installed the following version of PHP PHP 5.3.10 Build Date Feb 2 2012 20:26:31 Compiler MSVC9 (Visual C++ 2008)

PHP在静态页面上可以正常工作,但是问题在于尝试连接到MSSQL时.由于ASP和现有的MSSQL DB中有许多遗留代码,因此我们需要连接到MSSQL.

PHP works fine on static pages, but the issue is when trying to connect to MSSQL. We need to connect to MSSQL due to a lot of legacy code in ASP and an existing MSSQL DB.

我已经安装了SQL Native Client 2008,我已经安装了不止一次. 我检查了这些DLL,并将它们放在system32文件夹中.

I have SQL Native Client 2008 installed, I've installed it more than once. I checked and the DLLs are in system32 folder.

这是我正在加载的扩展程序

This is the extensions I'm loading

[PHP_SQLSRV_53_NTS_VC9]
extension=php_sqlsrv_53_nts_vc9.dll
[PHP_PDO_SQLSRV_53_NTS_VC9]
extension=php_pdo_sqlsrv_53_nts_vc9.dll

当我运行phpinfo时,列表中看不到sqlsrv驱动程序

When I run a phpinfo I can't see the sqlsrv driver in the list

我检查了PHP错误日志,并遇到以下错误

I checked the PHP error log and have the following error

[22-Mar-2012 14:04:27 UTC] PHP Warning:  PHP Startup: sqlsrv: Unable to initialize module
Module compiled with build ID=API20090626,NTS,VC9
PHP    compiled with build ID=API20090626,TS,VC9
These options need to match
 in Unknown on line 0
[22-Mar-2012 14:04:27 UTC] PHP Warning:  PHP Startup: pdo_sqlsrv: Unable to initialize     module
Module compiled with build ID=API20090626,NTS,VC9
PHP    compiled with build ID=API20090626,TS,VC9
These options need to match
 in Unknown on line 0

如果我将扩展名更改为使用线程安全并回收应用程序池,仍然会收到此错误.

If I change the extension to use Threaded Safe and recycle the application pool, still get this error.

我尝试过几次重新安装Native Client和PHP,但是没有运气.

I tried reinstalling Native Client and PHP a few times now but with no luck.

在sqlsrv无法识别本机客户端之前,我遇到了另一个错误,但是现在php无法识别sqlsrv.

I was getting a different error before that sqlsrv couldn't recognize native client but now php doesn't recognize sqlsrv.

更新

UPDATE

我设法使用正确的sqlsrv驱动程序,并且在php错误日志中没有错误

I managed to make it with the correct sqlsrv driver and no errors on the php errorlog

但是当使用此脚本连接或给我错误给sql

But when using this script to connect or give me error to sql

<?php
$serverName = 'DBSERVER';
$connParams = array('UID'=>'UID', 'PWD'=>'PASSWORD', 'Database'=>'DATABASENAME','ReturnDatesAsStrings'=> true);
$conn = sqlsrv_connect($serverName, $connParams);
if(!$conn){
    $errors = sqlsrv_errors();
    die(var_dump($errors));
}
sqlsrv_connect($conn);
die('connected');
?>

我收到此错误

> array(2) { [0]=> array(6) { [0]=> string(5) "IMSSP" ["SQLSTATE"]=>
> string(5) "IMSSP" [1]=> int(-49) ["code"]=> int(-49) [2]=> string(390)
> "This extension requires either the Microsoft SQL Server 2008 Native
> Client (SP1 or later) or the Microsoft SQL Server 2008 R2 Native
> Client ODBC Driver to communicate with SQL Server. Neither of those
> ODBC Drivers are currently installed. Access the following URL to
> download the Microsoft SQL Server 2008 R2 Native Client ODBC driver
> for x86: http://go.microsoft.com/fwlink/?LinkId=163712" ["message"]=>
> string(390) "This extension requires either the Microsoft SQL Server
> 2008 Native Client (SP1 or later) or the Microsoft SQL Server 2008 R2
> Native Client ODBC Driver to communicate with SQL Server. Neither of
> those ODBC Drivers are currently installed. Access the following URL
> to download the Microsoft SQL Server 2008 R2 Native Client ODBC driver
> for x86: http://go.microsoft.com/fwlink/?LinkId=163712" } [1]=>
> array(6) { [0]=> string(5) "IM002" ["SQLSTATE"]=> string(5) "IM002"
> [1]=> int(0) ["code"]=> int(0) [2]=> string(91) "[Microsoft][ODBC
> Driver Manager] Data source name not found and no default driver
> specified" ["message"]=> string(91) "[Microsoft][ODBC Driver Manager]
> Data source name not found and no default driver specified" } }

更新2

UPDATE 2

我安装了SQLCMD工具,它可以正确连接到服务器.

I installed SQLCMD tools and it connects correctly to the server.

DLL版本为

SQLNCLI10.DLL 2009.100.1600.1

SQLNCLI10.DLL 2009.100.1600.1

SQLSRV32.DLL 2000.85.1117.0 (我使用另一台服务器上的DLL更新了此文件,但仍然无济于事) 现在是版本6.1.7600.16385

SQLSRV32.DLL 2000.85.1117.0 (I Updated this one with the DLL from another server but still didn't help) It is now Version 6.1.7600.16385

如上所述,已安装Native Client 2008 R2(dll位于Windows \ system32中),并且数据库已启动并正在运行.如果我从另一台服务器运行相同的脚本,它将起作用.

As stated above, Native Client 2008 R2 is installed (the dlls are in windows\system32) and the DB is up and running. If I run the same script from another server it works.

我尝试对应用程序池,本机客户端dll和php扩展文件夹使用不同的权限,但是没有运气.

I tried with different permissions on the application pool, the native client dlls and php extension folder with no luck.

任何想法都很棒.

更新3

UPDATE 3

事实证明,这是一个权限问题!

As it turned out it was a permission issue!

我下载了Process Monitor,并按照这篇文章中的说明进行操作

I downloaded Process Monitor and followed the instructions on this post

http://www.iislogs.com/articles/processmonitorw3wp/

然后我看到进程w3wp.exe在此注册表项上的访问被拒绝

Then I saw the process w3wp.exe was getting access denied on this registry key

HKLM \ Software \ ODBC \ ODBCINST.INI \ SQL Native Client 10.0

HKLM\Software\ODBC\ODBCINST.INI\SQL Native Client 10.0

我打开RegEdit,然后转到该键.

I opened RegEdit and went to that key.

我确实右键单击->权限,并将网络服务"添加到列表中,并授予了读取"权限.

I did right click - > Permissions and added Network Service to the list and gave it Read permissions.

回收了应用程序池,它现在可以工作!

Recycled the app pool and it is now working!

干杯, 费德

推荐答案

原来是权限问题.

我在php.ini中将fastcgi.impersonate选项更改为0,然后尝试使用不同的应用程序池标识.它作为本地系统工作.这是一个比网络服务或本地服务帐户具有更多用户权限的帐户.但是,请注意,在具有增加的用户权限的帐户下运行应用程序池会带来很高的安全风险.有关帐户以及如何配置的更多参考,请查看以下文章:

I changed in php.ini the option fastcgi.impersonate to 0 and try with different application pool identities. It worked as Local System. This is an account with more user rights than the Network Service or Local Service account. However, be mindful that running an application pool under an account with increased user rights presents a high security risk. For further references on the accounts and how to configure check out this articles:

使用IIS 6.0(IIS 6.0)配置应用程序池标识 服务用户帐户 服务安全和访问权限

我决定将其设置回网络服务,并下载了Process Monitor *.然后,我用它来监视w3wp进程,这表明我的注册表项被拒绝访问,该注册表项存储了sqlncli.dll的路径.

I decided to set it back to Network Service and downloaded Process Monitor *. I then used it to monitor the process w3wp, which showed me this was getting access denied on a registry key where the path to sqlncli.dll is stored.

HKLM \ Software \ ODBC \ ODBCINST.INI \ SQL Native Client 10.0

HKLM\Software\ODBC\ODBCINST.INI\SQL Native Client 10.0

所以我打开RegEdit并找到了那个键

So I opened RegEdit and located that key

我确实右键单击->权限,并将网络服务"添加到列表中,并授予了读取"权限.

I did right click - > Permissions and added Network Service to the list and gave it Read permissions.

回收了应用程序池,它现在可以工作!

Recycled the app pool and it is now working!

希望这会有所帮助! 费德里科

Hope this helps! Federico

*这里有一篇很好的循序渐进文章,介绍如何使用过程监视器.

*There's a very good step by step article on how to use process monitor here.

http://www.iislogs.com/articles/processmonitorw3wp/

这篇关于PHP 5.3无法识别Native Client连接到MS SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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