這一點很容易做到,但是做完這樣的設置后還是連不上,錯誤的信息如下: MS SQL Server 數據庫連接錯誤!請檢查數據庫主機變量設置是否正確!!! 而主機的變量設置我是一遍一遍的檢查,那些設置是一點問題都沒有的,翻遍網頁,找到了下面的這點蛛絲馬跡:
php.com資料: I am trying to connect to SQL Server 2000 from PHP I bumped to following warning: Warning: mssql_connect(): Unable to connect to server: SERVER/Portal ....... on line 5 on line 5 there is: $db_connect = mssql_connect('SERVER/Portal', 'sa', 'my_passwd'); I did the following 1.enabled php_mssql.dll extension in PHP.ini 2.every dll is in proper place(System32 or PHP folder),including ntwdblib.dll I search lots of profile throught web ,but no one give me proper answer to resolve it. after a few hour ,I found the problem was caused by ntwdblib.dll ,which version is 7.00.839 ,when I replaced old ntwdblib.dll with the new ntwdblib.dll ,which version is 8.00.194 ,all problem are solved. We had some, read A LOT, of problems with MSSQL under Windows 2003. We had 2 the same windows, php, php-ini, everything machines but only one could connect. Unable to connect was the error message. Finnaly we checked the version of ntwdblib.dll and the one distributed with PHP was 7.00.... and the version of the one on the SQL Server install was 8.00.... so we copied this one in the php and apache dir and it worked. 問題就這樣被找到了,惹禍的是它 ntwdblib.dll ntwdblib.dll的主要作用是提供sql server連接服務。 我用的php版本是4.3.9,在安裝它的服器的 windows/system32/ 下我查到ntwdblib.dll文件的版本是2000.2.8.0 ,這個版本支持的是sql server 7.0, 因為安裝PHP時會把dlls下面的所有文件覆蓋到系統 目錄下,所以當我用它去連接 sql server 2000 的時候當然會是無法連接了。 后來我在一臺正常安裝sql server 2000 的服務器上查到 ntwdblib.dll的版本是 2000.80.2039.0,我把這個文件拷過去,覆蓋掉以前的版本,重啟服務器后,一切正常。 補充:如果數據庫名的開頭是數字時也會提示無法打開,這時要做的很簡單,把數據庫的名字用中括號 [ ] 括起來就搞定了,如 123bbs 改寫成 [123bbs]就沒有問題了,另外如果你的數據庫名字與sql server中的保留字沖突的話也會出現這種情況,用中括號的方法一樣可以解決。 最終,PHP無法正確連接sql server 2000的問題終于解決了,雖然耗費大半天的時間,但收獲還是很大的,現在把它貼出來,也讓遇到同樣問題的兄弟們少走一些彎路。