从安卓端post一个参数过来在php端接收后,在php端连接数据库并在数据库中查找包含该参数的数据,用select where语句无法成功

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条件的话运行完全没问题 

不知道问题出在哪里
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值