2008年(1812)
分类:
2008-05-03 20:10:51
WIN下比较简单:
1.安装SQL服务器并添加PHP的MSSQL扩展.(参见文章:win2000搭建PHP+Sql Server2000环境)
2.使用以下代码连接并测试
$myServer = "localhost"; //主机
$myUser = "sa"; //用户名
$myPass = "password"; //密码
$myDB = "Northwind"; //MSSQL库名
$s = @mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
$d = @mssql_select_db($myDB, $s)
or die("Couldn't open database $myDB");
$query = "SELECT TitleOfCourtesy ' ' FirstName ' ' LastName AS Employee ";
$query .= "FROM Employees ";
$query .= "WHERE Country='USA' AND Left(HomePhone, 5) = '(206)'";
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo ""
. $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned ";
while($row = mssql_fetch_array($result))
{
echo "
}
?>
代码来源:PHP手册
-------------------------------------------------
LINUX下的方法如下:(以TCP/IP 远程连接MSSQL)
1.安装freetds后.配置好.
一般是这样:
[MSSQL_2000]
host = 192.168.0.25
port = 1433
tds version = 8.0
2.编译PHP时.加上 --with-mssql=/freetbs的path
3.连接测试:
$msconnect=mssql_connect("MSSQL_2000","sa","");
$msdb=mssql_select_db("Northwind",$msconnect);
$msquery = "select titleofcourtesy,firstname,lastname from employees";
$msresults= mssql_query($msquery);
while ($row = mssql_fetch_array($msresults)) {
echo "
}
?>
WIN下比较简单:
1.安装SQL服务器并添加PHP的MSSQL扩展.(参见文章:win2000搭建PHP+Sql Server2000环境)
2.使用以下代码连接并测试
$myServer = "localhost"; //主机
$myUser = "sa"; //用户名
$myPass = "password"; //密码
$myDB = "Northwind"; //MSSQL库名
$s = @mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
$d = @mssql_select_db($myDB, $s)
or die("Couldn't open database $myDB");
$query = "SELECT TitleOfCourtesy ' ' FirstName ' ' LastName AS Employee ";
$query .= "FROM Employees ";
$query .= "WHERE Country='USA' AND Left(HomePhone, 5) = '(206)'";
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo ""
. $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned ";
while($row = mssql_fetch_array($result))
{
echo "
}
?>
代码来源:PHP手册
-------------------------------------------------
LINUX下的方法如下:(以TCP/IP 远程连接MSSQL)
1.安装freetds后.配置好.
一般是这样:
[MSSQL_2000]
host = 192.168.0.25
port = 1433
tds version = 8.0
2.编译PHP时.加上 --with-mssql=/freetbs的path
3.连接测试:
$msconnect=mssql_connect("MSSQL_2000","sa","");
$msdb=mssql_select_db("Northwind",$msconnect);
$msquery = "select titleofcourtesy,firstname,lastname from employees";
$msresults= mssql_query($msquery);
while ($row = mssql_fetch_array($msresults)) {
echo "
}
?>