我有一个调用远程 php 将数据插入 mysql 表的 Android java 方法。
这是java代码客户端:
public static void insert(String email1, String email2) {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("email1", email1));
nameValuePairs.add(new BasicNameValuePair("email2", email2));
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("myserver:8080/insert.php");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//How to catch and print php echo() here??
}
这是insert.php服务器端(重新编辑):
<?php
$mysqli_connection = new mysqli("localhost:3306", "root", "password", "mydb");
if ($mysqli_connection->connect_errno) {
echo ("Connection Failure");
exit();
}
$stmt = $mysqli->stmt_init();
if ($stmt->prepare("INSERT INTO `mytable` (`email1`, `email2`) VALUES (?,?)")) {
echo 'Success';
$stmt->bind_param("ss", $_GET['email1'], $_GET['email2']);
$stmt->execute();
$stmt->close();
} else {
echo 'Error Inserting Content';
}
$mysqli->close();
?>
当我调用我的 java insert() 方法时,没有返回异常,但没有插入,并且 mytable 为空。
- 1)怎么了?
- 2) 如何查看发生了哪个错误?如何查看 php 端执行的“日志”?
非常感谢。凝胶