title: Android, connecting to MySQL using PHP
body: <p>I am trying to connect to MySQL DB using php script. But I don't get any output only exception code. I can't figure it out where is the problem. I used a tutorial code.</p>
  
  <pre><code>private EditText outputStream;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      String result = null;
      InputStream input = null;
      StringBuilder sbuilder = null;
      outputStream = (EditText)findViewById(R.id.output);
      ArrayList &lt;NameValuePair&gt; nameValuePairs = new ArrayList &lt;NameValuePair&gt;();
  
      try{
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("http://ik.su.lt/~jbarzelis/Bandymas/index.php");
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
          HttpResponse response = httpclient.execute(httppost);
          HttpEntity entity = response.getEntity();
          input = entity.getContent();
      }
      catch(Exception e){
          Log.e("log_tag","Error in internet connection"+e.toString());
      }
      try{
          BufferedReader reader = new BufferedReader(new InputStreamReader(input,"iso-8859-1"),8);
          sbuilder = new StringBuilder();
  
          String line = null;
  
          while((line = reader.readLine()) != null){
              sbuilder.append(line + "\n");
              System.out.println(line);
          }
          input.close();
          result = sbuilder.toString();
      }
      catch(Exception e){
          Log.e("log_tag", "Error converting result "+e.toString());          
      }
      int fd_id;
      String fd_name;
      try{
          JSONArray jArray = new JSONArray(result);
          JSONObject json_data = null;
          for(int i=0;i&lt;jArray.length();i++){
              json_data = jArray.getJSONObject(i);
              fd_id = json_data.getInt("FOOD_ID");
              fd_name = json_data.getString("FOOD_NAME");
              outputStream.append(fd_id +" " + fd_name + "\n");
          }
  
  
          }
      catch(JSONException e1){
          Toast.makeText(getBaseContext(), "No food found", Toast.LENGTH_LONG).show();
      }
      catch(ParseException e1){
          e1.printStackTrace();
      }
  }
  </code></pre>
  
  <p>PHP script: </p>
  
  <pre><code>&lt;?php
  mysql_connect("localhost","**********","******");
  mysql_select_db("test");
  $sql = mysql_query("select FOOD_NAME as 'Maistas' from FOOD where FOOD_NAME like 'A%'");
  while($row = mysql_fetch_assoc($sql)) $output[]=$row;
  print(json_encode($output));
  mysql_close;
  </code></pre>
  
  <p>?></p>
  
  <p>Any ideas how to fix it?</p>