<?php //mssql.secure_connection = On // Need to upload ntwdblib.dll from net $myServer = ".\SQLEXPRESS"; // host/instance_name $myUser = "sa"; // username $myPass = "xxxxxxxx"; // paasword $myDB = "mydb"; // database name // connection to the database $dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn’t connect to SQL Server on $myServer"); // select a database to work with $selected = mssql_select_db($myDB, $dbhandle) or die("Couldn’t open database $myDB"); echo "You are connected to the " . $myDB . " database on the " . $myServer . "."; $query = "SELECT top 10 * FROM Account"; // your database query $result = mssql_query($query); while($row = mssql_fetch_assoc($result)) { print_r($row); } // close the connection mssql_close($dbhandle); ?>
在連接 mssql 時出現這個問題
“Warning mssql_connect()[function.mssql-connect]: Unable to connect to server:”
解決方法
1.修改 php.ini 打開php.ini
找到 ;extension=php_mssql.dll
打extension=php_mssql.dll 前面的 “;” 刪除便可以了
2.下載 ntwdblib.dll
之後把他複製/取代 你電腦上的
Apache/bin/ntwdblib.dll 和 php/ntwdblib.dll
3. Apache Restart
再測就OK了