$conn=mssql_connect("xxh","sa",""); //定义并打开连接
mssql_select_db("HelloPHP");//选择数据库
$query="select * from Users";//定义查询串
$result=mssql_query($query);//打开查询结果集
$row=mssql_fetch_array($result);//取一行
while($row) //遍历所有记录
{
echo("<br>");
print_r($row);//打印记录数组
echo("<br>");
$row=mssql_fetch_array($result);
}
在这里,取一行记录我测试了两个函数:
1.mssql_fetch_array
该函数返回的数组是这样的:
Array ( [0] => 01001 [Code] => 01001 [1] => sys [Name] => sys [2] => 0 [Password] => 0 )
Array ( [0] => 01002 [Code] => 01002 [1] => users [Name] => users [2] => 0 [Password] => 0 )
即可以用0,1,2索引来访问结果集,也可以用字段名字来访问结果集。
2.mssql_fetch_row
该函数返回的数组是这样的:
Array ( [0] => 01001 [1] => sys [2] => 0 )
Array ( [0] => 01002 [1] => users [2] => 0 )
只能用0,1,2索引来访问结果集。