title: How to connect Android emulator with local mysql database
body: <p>I want to connect mysql database locally with android emulator. I used http GET and POST methods for accessing data from Google Cloud SQL with app engine but i want to connect it with locally using phpmyadmin..</p>
  
  <p>when i use following code it show Toast for connection failed</p>
  
  <pre><code>        String result = "";
          //the year data to send
          ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
          nameValuePairs.add(new BasicNameValuePair("name","Hammad"));
  
          //http post
          try{
                  HttpClient httpclient = new DefaultHttpClient();
                  HttpPost httppost = new HttpPost("http://localhost/myApp/read_data.php");
                  httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                  HttpResponse response = httpclient.execute(httppost); 
                  HttpEntity entity = response.getEntity();
                  is = entity.getContent();
  
                  Log.e("log_tag", "connection success ");
                  Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show();
          }catch(Exception e){
                  Log.e("log_tag", "Error in http connection "+e.toString());
                  Toast.makeText(getApplicationContext(), "Connection fail", Toast.LENGTH_SHORT).show();
  
          }
          //convert response to string
          try{
                  BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                  StringBuilder sb = new StringBuilder();
                  String line = null;
                  while ((line = reader.readLine()) != null) {
                          sb.append(line + "\n");
                          Toast.makeText(getApplicationContext(), "Input Reading pass", Toast.LENGTH_SHORT).show();
                  }
                  is.close();
  
                  result=sb.toString();
          }catch(Exception e){
                 Log.e("log_tag", "Error converting result "+e.toString());
              Toast.makeText(getApplicationContext(), " Input reading fail", Toast.LENGTH_SHORT).show();
  
          }
  
          //parse json data
          try{
                  JSONArray jArray = new JSONArray(result);
                  for(int i=0;i&lt;jArray.length();i++){
                         JSONObject json_data = jArray.getJSONObject(i);
                          Log.i("log_tag","id: "+json_data.getInt("user_id")+
                                  ", Username: "+json_data.getString("username")+
                                  ", Name: "+json_data.getInt("name")+
                                  ", City: "+json_data.getInt("city")
                          );
                          Toast.makeText(getApplicationContext(), "JsonArray pass", Toast.LENGTH_SHORT).show();
                 }
  
          }catch(JSONException e){
                  Log.e("log_tag", "Error parsing data "+e.toString());
                  Toast.makeText(getApplicationContext(), "JsonArray fail", Toast.LENGTH_SHORT).show();
          }
      }
  
    }
  </code></pre>