安卓端post参数在php端接收后,在php端连接数据库并查找包含该参数的数据,用select where语句无法成功
PHP端代码如下<?php//连接数据库$serverName="192.168.208.42";$uid="sa";$pwd="sadell";$database="m...
PHP端代码如下
<?php
//连接数据库
$serverName = "192.168.208.42";
$uid = "sa";
$pwd = "sadell";
$database = "my_db";
$connectionInfo = array("PWD"=>$pwd,"UID"=>$uid,"Database"=>$database);
$con = sqlsrv_connect($serverName,$connectionInfo);
$result = "SELECT * FROM NFC2 WHERE id='$_POST[id]'"; //在数据库中查找id为post过来的数据的行
$rresult=sqlsrv_query($con,$result,array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
$Rows=sqlsrv_num_rows($rresult); //获得行数
if ($Rows != 0){echo "Get Permisson"+$Rows;} //如果行数不等于0,则说明数据库中有该记录,获得许可,把该记录的数量显示出来
else {echo "NO Permisson";}
?>
运行后错误代码 sqlsrv_num_row expected parameter 1 to be resource, boolean given in.....
于是我把 $Rows=sqlsrv_num_rows($rresult); 改为 $Rows=sqlsrv_num_rows($con,$rresult); 运行后错误信息Fatal error: Param count and argument count don't match.
然而我不加WHERE条件的话运行完全没问题 展开
<?php
//连接数据库
$serverName = "192.168.208.42";
$uid = "sa";
$pwd = "sadell";
$database = "my_db";
$connectionInfo = array("PWD"=>$pwd,"UID"=>$uid,"Database"=>$database);
$con = sqlsrv_connect($serverName,$connectionInfo);
$result = "SELECT * FROM NFC2 WHERE id='$_POST[id]'"; //在数据库中查找id为post过来的数据的行
$rresult=sqlsrv_query($con,$result,array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
$Rows=sqlsrv_num_rows($rresult); //获得行数
if ($Rows != 0){echo "Get Permisson"+$Rows;} //如果行数不等于0,则说明数据库中有该记录,获得许可,把该记录的数量显示出来
else {echo "NO Permisson";}
?>
运行后错误代码 sqlsrv_num_row expected parameter 1 to be resource, boolean given in.....
于是我把 $Rows=sqlsrv_num_rows($rresult); 改为 $Rows=sqlsrv_num_rows($con,$rresult); 运行后错误信息Fatal error: Param count and argument count don't match.
然而我不加WHERE条件的话运行完全没问题 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询