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";}
?>
下面是安卓端该线程代码
new Thread(new Runnable() {
public void run()
{
ArrayList params = new ArrayList();
params.add(new BasicNameValuePair("id",ByteArrayToHexString(id)));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.210.51/NFC.php");
httppost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse=new DefaultHttpClient().execute(httppost);
if(httpResponse.getStatusLine().getStatusCode()==200){
String result = EntityUtils.toString(httpResponse.getEntity());
if(result.equals("Get Permisson")){
Looper.prepare();
Toast toast=Toast.makeText(getApplicationContext(),result, Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP| Gravity.CENTER, -50, 100);
toast.show();
Looper.loop();
}
else{
Looper.prepare();
Toast toast=Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP|Gravity.CENTER, -50, 100);
toast.show();
Looper.loop();
}
}
} catch (Exception e) {
}
};
}) { }.start();
}
运行后错误代码 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";}
?>
下面是安卓端该线程代码
new Thread(new Runnable() {
public void run()
{
ArrayList params = new ArrayList();
params.add(new BasicNameValuePair("id",ByteArrayToHexString(id)));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.210.51/NFC.php");
httppost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse=new DefaultHttpClient().execute(httppost);
if(httpResponse.getStatusLine().getStatusCode()==200){
String result = EntityUtils.toString(httpResponse.getEntity());
if(result.equals("Get Permisson")){
Looper.prepare();
Toast toast=Toast.makeText(getApplicationContext(),result, Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP| Gravity.CENTER, -50, 100);
toast.show();
Looper.loop();
}
else{
Looper.prepare();
Toast toast=Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP|Gravity.CENTER, -50, 100);
toast.show();
Looper.loop();
}
}
} catch (Exception e) {
}
};
}) { }.start();
}
运行后错误代码 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条件的话运行完全没问题
不知道问题出在哪里