我在服务器上配置了PHP运行环境,系统是:win2008+IIS7+PHP5.3.2+SQL2005  配置好后,能正常打开PHP页面。但是连接数据库时,总是报以下错误:
Unable to connect.
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 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序 ) )在WIN7下面测试也是报这个错误。但在WIN2003下面程序是正常的。数据库连接代码如下:
<?php  
  $serverName = "127.0.0.1";   
  $uid = "sa";  
  $pwd = "123456";  
  $connectionOptions = array("UID" => $uid, "PWD" => $pwd, "Database"=>"agency");  
  $conn = sqlsrv_connect( $serverName, $connectionOptions );  
if( $conn === false )  
{  
     echo "Unable to connect.</br>";  
     die( print_r( sqlsrv_errors(), true));  
}  
  $tsql = "SELECT * FROM proprty";  
  $getProducts = sqlsrv_query( $conn, $tsql );  
  while( $row = sqlsrv_fetch_array( $getProducts, SQLSRV_FETCH_ASSOC ) )   
  {   
    print_r( $row );   
  }  
  echo "<br/>";  
  
  sqlsrv_free_stmt( $getProducts );  
  sqlsrv_close( $conn );  
?>   PHP数据库连接MSSQL