主题:关于php在windows下链接的问题
fuweijun
[专家分:1930] 发布于 2007-03-28 11:13:00
php在windows xp下链接mssql2000 的语句有人能帖出来一下吗?
回复列表 (共2个回复)
沙发
一个人住 [专家分:3290] 发布于 2007-03-29 08:49:00
WIN下比较简单:
1.安装SQL服务器并添加PHP的MSSQL扩展.
2.使用以下代码连接并测试
<?php
$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 "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["Employee"] . "</li>";
}
?>
代码来源: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 "<li>" . $row['titleofcourtesy'] . " " . $row['firstname'] . " " . $row['lastname'] . "</li>\n";
}
?>
板凳
fuweijun [专家分:1930] 发布于 2007-03-29 09:55:00
不胜感激
我来回复