通过PHP连接到SQL Server 2008 [英] Connecting to SQL Server 2008 through PHP

查看:99
本文介绍了通过PHP连接到SQL Server 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过PHP(WAMP,最新版本)连接到SQL Server 2008.我已经安装并设置了sqlsrv驱动程序,它们确实显示在phpinfo()中.

I need to connect to a SQL Server 2008 through PHP (WAMP, latest version). I have the sqlsrv drivers installed and set up and they do show up in phpinfo().

我正在使用以下行通过Windows身份验证连接到我的数据库:

I'm using the following lines to connect to my DB, using Windows Authentication:

$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的解决方法.

Any help would be great, but please be specific since I really don't know my way around WAMP except for a few basics.

推荐答案

该错误是由注册表中的权限问题引起的.有一个密钥可以存储到本机客户端的路径,并且您在应用程序池中使用的身份将被拒绝访问.

The error is caused by a permission issue in the registry. There is a key where the path to the native client is stored and the identity you are using in the application pool is getting denied access.

  • 下载Process Monitor并按照此职位上的说明进行操作: http://www.iislogs.com/articles/processmonitorw3wp/(本教程介绍了如何使用WAMP在IIS上执行此操作,您将需要找到在内存上运行的.exe进程)
  • 查找拒绝访问进程w3wp.exe的注册表项.对于IIS,不确定WAMP中进程的名称是什么,但过程相同. 就我而言:

  • Download Process Monitor and follow the instructions on this post: http://www.iislogs.com/articles/processmonitorw3wp/ (This tutorial shows how to do it on IIS, with WAMP you will need to find the .exe process that runs on memory)
  • Find the registry key where the process w3wp.exe is being denied access. That in the case of IIS, not sure what's the name of the process in WAMP but the procedure is the same. In my case:

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

  • 运行regedit并找到密钥
  • 右键单击并转到权限
  • 将网络服务添加到列表中,并授予其读取权限.
  • 回收应用程序池,它应该可以工作
  • Run regedit and find the key
  • Right click and go to Permissions
  • Add Network Service to the list and give it Read permissions.
  • Recycle the app pool and it should work
  • 这篇关于通过PHP连接到SQL Server 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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