无法连接到MSSQL Server

时间:2015-08-31 08:15:07

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

当我尝试使用以下代码建立与MSSQL Server的连接时:

try {
$c_info = array("Database" => "ddb", "UID" => "sa", "PWD" => "admin123");
echo var_dump(sqlsrv_errors(SQLSRV_ERR_ALL));

$db = sqlsrv_connect('LENOVOWIH\SQLEXPRESS', $c_info); // Make a connection to MSSQL
if($db) echo '\ntrue';
else echo "\nfalse : " . var_dump(sqlsrv_errors());
}  catch(Exception $e) {
      echo $e . " " . sqlsrv_errors();
   }

var_dump(sqlsrv_errors())发出:

    array (size=2)
  0 => 
    array (size=6)
      0 => string 'IMSSP' (length=5)
      'SQLSTATE' => string 'IMSSP' (length=5)
      1 => int -49
      'code' => int -49
      2 => string 'This extension requires the ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712' (length=184)
      'message' => string 'This extension requires the ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712' (length=184)
  1 => 
    array (size=6)
      0 => string 'IM002' (length=5)
      'SQLSTATE' => string 'IM002' (length=5)
      1 => int 0
      'code' => int 0
      2 => string '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified' (length=91)
      'message' => string '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified' (length=91)

我已将extension=php_sqlsrv_55_ts.dll放入php.ini (\ wamp \ bin \ apache \ apache2.4.9 \ bin \ php.ini)文件中dllext目录中。我正在使用php版本5.5.12

的wampp

这可能是什么原因?

1 个答案:

答案 0 :(得分:0)

安装ODBC driver。 sqlsrv驱动程序基于ODBC构建,由Microsoft主动维护,并提供对SQL Server最新版本中的功能的访问。

enter image description here