0
I am 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 executaeQuery.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 a lot more direct access to the executaeQuery.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
The error shown is not from the Mysql server not connecting, but from the PHP application server that is not responding. How are you running the PHP application? You can access it in the browser using the address
http://192.168.0.2
?– elias