Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost
PHP 自帶的 ntwdblib.dll 版本為 7.0(用於 SQL Server 7.0),而目標數據庫為 SQL Server 2000/2005/2008,協議不兼容導致連接失敗。
ntwdblib.dll(通常在 C:\Program Files\Microsoft SQL Server\80\Tools\Binn\),版本應為 2000.80.xxx。C:\php\ntwdblib.dll)。C:\Windows\System32\(備用)。<?php
$conn = mssql_connect('localhost', 'sa', 'password') or die('連接失敗');
echo mssql_get_last_message(); // 獲取詳細錯誤信息
?>
pecl install sqlsrv pdo_sqlsrv若必須繼續使用古老 mssql 擴展(PHP 5.3 後已移除),請鎖定 PHP 5.2 版本並在隔離環境運行,規劃遷移路線圖。