我需要通过 PHP(WAMP,最新版本)连接到 SQL Server 2008。我安装并设置了 sqlsrv 驱动程序,它们确实显示在 phpinfo()
中。
我使用以下行连接到我的数据库,使用 Windows 身份验证:
$serverName = "(local)";
$connectionOptions = array("Database"=>"MyTestDatabase");
$conn = sqlsrv_connect( $serverName, $connectionOptions) or die("Error!");
我收到以下错误:
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -49
[code] => -49
[2] => This extension requires the Microsoft SQL Server 2011 Native Client. Access the following URL to download the Microsoft SQL Server 2011 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
[message] => This extension requires the Microsoft SQL Server 2011 Native Client. Access the following URL to download the Microsoft SQL Server 2011 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
)
[1] => Array
(
[0] => IM002
[SQLSTATE] => IM002
[1] => 0
[code] => 0
[2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
[message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
)
)
任何帮助都会很好,但请具体说明,因为除了一些基础知识外,我真的不知道如何使用 WAMP。
最佳答案
该错误是由注册表中的权限问题引起的。有一个存储本地客户端路径的 key ,您在应用程序池中使用的身份被拒绝访问。
- 下载 Process Monitor 并按照此帖子中的说明进行操作: http://www.iislogs.com/articles/processmonitorw3wp/ (本教程展示了如何在 IIS 上执行此操作,对于 WAMP,您将需要找到在内存上运行的 .exe 进程)
找到进程
w3wp.exe
被拒绝访问的注册表项。在 IIS 的情况下,不确定 WAMP 中进程的名称是什么,但过程是相同的。 就我而言:HKLM\Software\ODBC\ODBCINST.INI\SQL Native Client 10.0
- 运行 regedit 并找到 key
- 右键单击并转到“权限”
- 将网络服务添加到列表中并授予其读取权限。
- 回收应用程序池,它应该可以工作
关于php - 通过 PHP 连接到 SQL Server 2008,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9254329/