sqlsrv_connect:未找到数据源名称且未指定默认驱动程序

时间:2012-11-09 09:25:10

标签: php sql-server sql-server-2008 wamp

我在将PHP与在远程计算机上运行的SQL SERVER 2008连接时遇到了困难。我有php版本5.4.3和apache 2.2.22。我已经在我的计算机上运行了SQL SERVER 2008。我的wamp \ bin \ php \ php5.4.3 \ ext文件夹中包含以下文件:

  • php_sqlsrv_54_ts.dll
  • php_pdo_sqlsrv_54_ts.dll

运行简单的代码,如

$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn )
{
 echo "Connection established.\n";
}
else
{
 echo "Connection could not be established.\n";
 die( print_r( sqlsrv_errors(), true));
}

我收到以下错误:

Connection could not be established. Array (
    [0] => Array (
        [0] => IMSSP [SQLSTATE] => IMSSP
        [1] => -49 [code] => -49
        [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 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
    )
) 

但我不知道为什么要求我安装 Microsoft SQL Server 2012 Native Client

phpI尝试了this link但没有成功。

先谢谢。

更新1:

我下载了php 5.3.1并关注this tutorial,脚本就像魅力一样。

2 个答案:

答案 0 :(得分:2)

根据requirements:SQLSRV扩展要求在运行PHP的同一台计算机上安装Microsoft SQL Server 2012 Native Client。

答案 1 :(得分:0)

安装ODBC驱动程序(https://www.microsoft.com/en-us/download/details.aspx?id=36434)。 现在我可以访问远程MSSQL Server而无需在我的计算机中安装MSSQL Server