后台任务不调用php页面
嘿,我有一个php文件,它通过id从mysqli表中删除一个表行,我使用android AsyncTask执行它,但出于某种原因,它什么都不做,但当我单独使用定义的id参数执行php代码时,它工作正常,有人能告诉我问题出在哪里吗 这是php文件后台任务不调用php页面,php,android,Php,Android,嘿,我有一个php文件,它通过id从mysqli表中删除一个表行,我使用android AsyncTask执行它,但出于某种原因,它什么都不做,但当我单独使用定义的id参数执行php代码时,它工作正常,有人能告诉我问题出在哪里吗 这是php文件 <?php header('Content-Type: text/html; charset=utf-8'); $db = new PDO('mysql:host=******;dbname=****_ori;charset=utf8m
<?php
header('Content-Type: text/html; charset=utf-8');
$db = new PDO('mysql:host=******;dbname=****_ori;charset=utf8mb4', '******', '*****8');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$my_id = $_POST["pid"];
$stmt = $db->query("DELETE FROM table WHERE id = ?");
$stmt->bindParam(1,$my_id);
$stmt->execute();
?>
}当它什么都不做时,您可以记录HTTP请求/响应吗?为什么不将结果和变量值记录在一个简单的文本文件中,以了解什么是错误的,原因看起来很好。当它什么都不做时,你能记录HTTP请求/响应吗?为什么不把结果和变量值记录在一个简单的文本文件中,以了解什么是错误的,原因看起来很好。
@Override
protected String doInBackground(String... strings) {
id = strings[0];
String insertUrl = "http://website/delete_id.php";
try {
URL url = new URL(insertUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String data = URLEncoder.encode("pid", "UTF-8") + "=" + URLEncoder.encode("80", "UTF-8");
bufferedWriter.write(data);
Log.d("del",data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
httpURLConnection.disconnect();
return "done";
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "not";
}