操作系统:WIN7 sp1
Apache2.2 + PHP5.2.7(vc6+ts)连接SQL SERVER 2005(SP4)数据库,Apache和PHP已安装好并能正常显示,
源文件如下:
<?php
/*
Connect to the local server using Windows Authentication and specify
the AdventureWorks database as the database in use. To connect using
SQL Server Authentication, set values for the "UID" and "PWD"
 attributes in the $connectionInfo parameter. For example:
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>"AdventureWorks");
*/
$serverName = "(local)";
$connectionInfo = array( "Database"=>"AdventureWorks");
$conn = sqlsrv_connect( $serverName, $connectionInfo);if( $conn )
{
  echo "Connection established.\n";
}
else
{
  echo "Connection could not be established.\n<br>";
  die( print_r( sqlsrv_errors(), true));
}//-----------------------------------------------
// Perform operations with connection.
//-----------------------------------------------/* Close the connection. */
//sqlsrv_close( $conn);
?>
页面报错信息如下:
Connection could not be established.  
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => 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] => 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 ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序 [message] => [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序 ) )  
请高手大侠们分析下原因,不甚感激!emal:[email protected]

解决方案 »

  1.   

    从英文大意来看。是说要你下载Microsoft SQL Server 2008 R2 Native Client ODBC Driver这个驱动来交互SQLVER
      

  2.   

    1、似乎 sqlsrv 函数组是供 php5.3 使用的,能在 php5.2 中使用吗?未用过,不好说
    2、php5.2 连接 sql server 2005 只需使用 mssql 函数组就可以了
    3、尝试将服务器名由 (local) 改为 机器名