I'm trying to make a simple query using a PHP webservice. This is my current code:
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id", "1"));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://192.168.0.2/executeQuery.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
And this is executeQuery.php
<?php
mysql_connect("localhost:3306","root","password");
mysql_select_db("database");
$q=mysql_query("SELECT * FROM users WHERE id = '".$_REQUEST['id']."'");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
Is there something wrong? Although my server is working fine more direct access to executeQuery.php, I'm getting this exception:
org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.0.2 refused
Error converting result java.lang.NullPointerException