sqlsrv函数问题

WBOY
Release: 2016-06-23 14:12:55
Original
1195 people have browsed it

MS SQL sqlsrv PHP5.3.5

环境:Apache 2.2.22、PHP 5.3.5、数据库MSSQL2008
mssql这是PHP5.3以前版本的,怎么将以下代码改成PHP5.3之后版本的,即sqlsrv函数,自己曾试着改过一部分,但老是报错,所有只能在此求助各位了!!
<?	session_start();//连接数据库服务器	$Link=mssql_connect(".","sa","");//选择数据库	mssql_select_db("frienddb");//定义SQL语句		$name=$_REQUEST["txtName"];		$address=$_REQUEST["txtAddress"];	$group=$_REQUEST["txtGroup"];		$sqlstr="";	if($name!="")	{		$sqlstr="mName='".$name."'";	}		if($sqlstr!="")	{		if($address!="")		{			$sqlstr=$sqlstr." and mAddress='".$address."'";		}	}	else	{		if($address!="")		{			$sqlstr="mAddress='".$address."'";		}	}		if($sqlstr!="")	{		if($group!="")		{			$sqlstr=$sqlstr." and tname='".$group."'";		}	}	else	{		if($group!="")		{			$sqlstr="tname='".$group."'";		}	}			if($_REQUEST["Submit"]!="")	{		$_SESSION["sqltxt"]=$sqlstr;	}	else	{		$sqlstr=$_SESSION["sqltxt"];	}	echo $_SESSION["sqltxt"];		if($sqlstr!="")	{		$Query="select count(*) from myfriends,team where myfriends.tid=team.tid and ".$sqlstr;	}	else	{		$Query="select count(*) from myfriends,team where myfriends.tid=team.tid ";	}		$rs=mssql_query($Query);//查询记录总数	$cntrow=mssql_fetch_row($rs);	$cnt=$cntrow[0];//记录总数	$PageSize=10;//每页显示10条数据	//计算总页数	if($cnt%$PageSize==0)	{		$PageCnt=$cnt/$PageSize;	}	else	{		$PageCnt=floor($cnt/$PageSize)+1;//总页数	}	$CurrentPage=floor($_REQUEST["pid"]);//当前页,如果为小数则当前页取值为小于此小数的整数	//当前页小于1	if($CurrentPage<1)	{		$CurrentPage=1;	}	//当前页大于总页数	if($CurrentPage>$PageCnt)	{		$CurrentPage=$PageCnt;	}		//设置起始页码	$Start=$CurrentPage-3;	//设置终止页码		$End=$CurrentPage+3;			//上一页	$PrvPage=$CurrentPage-1;	//下一页	$NextPage=$CurrentPage+1;		if($Start<1)	{		$Start=1;		$End=$Start+6;	}		if($End>$PageCnt)	{		$Start=$PageCnt-6;		$End=$PageCnt;	}		if($sqlstr!="")	{		$sqlstr="select top ".$PageSize." mName,mSex,mBirthday,mTel,mAddress,tname from myfriends,team where myfriends.tid=team.tid and mid not in (select top ".($CurrentPage-1)*$PageSize." mid from myfriends) and ".$sqlstr;		}	else	{		$sqlstr="select top ".$PageSize." mName,mSex,mBirthday,mTel,mAddress,tname from myfriends,team where myfriends.tid=team.tid and mid not in (select top ".($CurrentPage-1)*$PageSize." mid from myfriends)  ";	}	//echo $sqlstr;		$result=mssql_query($sqlstr);//返回结果集	/*	mssql_fetch_row//取行数据	mssql_fetch_field//取列数据	*/		?><html><title></title><head></head><link href="css/demo.css" type="text/css" rel="stylesheet" rev="stylesheet"/><body><form><div id="outDiv">	<table border="1" id="maintable" style="width:60%">	<tr>		<?			for($j=0;$j<6;$j++)			{				$field=mssql_fetch_field($result);				echo "<td>".$field->name."</td>";			}		?>	</tr>	<? while($row=mssql_fetch_row($result))		{	 ?>	  <tr>	  <?		for($i=0;$i<count($row);$i++)		{			echo "<td>$row[$i]</td>";		}	  ?>	  </tr>	 <?		}	 ?>		<?		if($CurrentPage==1)		{						$PrvLink="<li class=\"nolink\">&laquo; Previous Page</li>";			$NextLink="<li><a href=\"newpage.php?pid=$NextPage\">Next Page &raquo;</a></li>";		}		else if($CurrentPage==$PageCnt)		{			$PrvLink="<li><a href=\"newpage.php?pid=$PrvPage\">&laquo; Previous Page</a></li>";			$NextLink="<li class=\"nolink\">Next Page &raquo;</li>";		}		else		{			$PrvLink="<li><a href=\"newpage.php?pid=$PrvPage\">&laquo; Previous Page</a></li>";			$NextLink="<li><a href=\"newpage.php?pid=$NextPage\">Next Page &raquo;</a></li>";		}	?>		<tr>		<td colspan="6">		<div id="pages">			<ul>			<?=$PrvLink?>			<?			for($p=$Start;$p<=$End;$p++)			{				if($p==$CurrentPage)				{					echo "<li class=\"current\">$p</li>";				}				else				{			?>			<li><a href="newpage.php?pid=<?=$p?>"><?=$p?></a></li>			<?				}			}			?>			<?=$NextLink?>			</ul>		</div>		</td>	</tr>		</table>	</div></form></body></html>
Copy after login

回复讨论(解决方案)

一般的,将mssql 换为 sqlsrc 就可以了,但是要注意各个参数的位置和含义。
还有有些函数sqlsrv_没有,比如 mssql_fetch_row 对应的 sqlsrv_fetch_row 就没有,用 sqlsrv_fetch_array/sqlsrv_fetch_objec 代替。

具体参考手册吧

一般的,将mssql 换为 sqlsrc 就可以了,但是要注意各个参数的位置和含义。
还有有些函数sqlsrv_没有,比如 mssql_fetch_row 对应的 sqlsrv_fetch_row 就没有,用 sqlsrv_fetch_array/sqlsrv_fetch_objec 代替。

具体参考手册吧
可以提供这方面的手册参考吗?在网上下载了很多PHP手册,都没有这个函数的(sqlsrv)

http://www.php.net/manual/zh/book.sqlsrv.php

http://php.net/manual/zh/book.sqlsrv.php

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template