我们在
上运行服务器Windows Server 2003 32位IIS6.0(我们有一些使用32位组件的经典ASP应用程序,因此我们无法升级到2008 64位)
我们的数据库服务器位于运行的单独计算机上 Windows Server 2008 64位 MS SQL 2008 R2 64位
我安装了以下版本的PHP PHP 5.3.10 建立日期2012年2月2日20:26:31 编译器MSVC9(Visual C ++ 2008)
PHP在静态页面上运行良好,但问题是在尝试连接到MSSQL时。由于ASP和现有的MSSQL DB中存在许多遗留代码,我们需要连接到MSSQL。
我安装了SQL Native Client 2008,我已多次安装它。 我检查了,DLL在system32文件夹中。
这是我正在加载的扩展程序
[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驱动程序
我检查了PHP错误日志并出现以下错误
[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
如果我更改扩展程序以使用Threaded Safe并回收应用程序池,仍然会收到此错误。
我现在尝试重新安装Native Client和PHP几次但没有运气。
在sqlsrv无法识别本机客户端但现在php无法识别sqlsrv之前,我得到了一个不同的错误。
的更新 的
我设法使用正确的sqlsrv驱动程序并且在php errorlog上没有错误
但是当使用这个脚本连接或给我错误的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
我安装了SQLCMD工具,它正确连接到服务器。
DLL版本
SQLNCLI10.DLL 2009.100.1600.1
SQLSRV32.DLL 2000.85.1117.0 (我用另一台服务器的DLL更新了这个,但仍然没有帮助) 它现在是版本6.1.7600.16385
如上所述,安装了Native Client 2008 R2(dll位于windows \ system32中),并且数据库已启动并正在运行。如果我从另一台服务器运行相同的脚本,它就可以工作。
我尝试了对应用程序池,本机客户端dll和php扩展文件夹的不同权限,但没有运气。
任何想法都会很棒。
更新3
事实证明这是一个许可问题!
我下载了Process Monitor并按照此帖子上的说明进行操作
http://www.iislogs.com/articles/processmonitorw3wp/
然后我看到进程w3wp.exe在此注册表项上被拒绝访问
HKLM \ Software \ ODBC \ ODBCINST.INI \ SQL Native Client 10.0
我打开RegEdit并转到那把钥匙。
我点击了右键 - &gt;权限并将网络服务添加到列表中并为其授予读取权限。
回收了应用程序池,它现在正在运行!
干杯, FEDE
答案 0 :(得分:4)
原来是一个许可问题。
我在php.ini中将fastcgi.impersonate选项更改为0并尝试使用不同的应用程序池标识。它作为本地系统工作。这是一个拥有比网络服务或本地服务帐户更多用户权限的帐户。但是,请注意,在具有增加的用户权限的帐户下运行应用程序池会带来很高的安全风险。有关帐户和如何配置的进一步参考,请查看以下文章:
Configuring Application Pool Identity with IIS 6.0 (IIS 6.0) Service User Accounts Service Security and Access Rights
我决定将其设置回网络服务并下载Process Monitor *。然后我用它来监视进程w3wp,这表明我在存储sqlncli.dll路径的注册表项上被拒绝访问。
HKLM \ Software \ ODBC \ ODBCINST.INI \ SQL Native Client 10.0
所以我打开了RegEdit并找到了那个键
我点击了右键 - &gt;权限并将网络服务添加到列表中并为其授予读取权限。
回收了应用程序池,它现在正在运行!
希望这有帮助! 费德里科
*这里有一篇关于如何使用流程监控器的非常好的分步文章。
答案 1 :(得分:0)
我遇到了相同的编译器版本问题,并使用PHP的ODBC驱动程序解决了它:
//$pdo = new PDO("sqlsrv:Server=$hostname;Database=$dbname;", $username, $password); // works with proper driver for PHP.
$pdo = new PDO("odbc:Driver={SQL Server};Server=$hostname;Database=$dbname;", $username, $password); // works with proper driver for ODBC and PHP ODBC.