2015-08-31 224 views
0

當我嘗試使用下面的代碼做出MSSQL Server連接:無法連接到MSSQL服務器

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目錄中。我正在使用wampp和php版本5.5.12

這可能是什麼原因?

+0

您可以從其他客戶端連接嗎?也許你需要安裝https://www.microsoft.com/en-us/download/details.aspx?id=36434 – Mate

+0

@Mate我可以連接到'MySQL' –

+0

@Mate我安裝了ODBC驅動程序,它工作。您能否簡要回答一下我的錯誤,以及ODBC驅動程序的用途。 –

回答

0

安裝ODBC driver。 sqlsrv驅動程序構建於ODBC上,由Microsoft主動維護,並提供對最新版本SQL Server中功能的訪問。

enter image description here