Having Problem With php, mysql and android

  • Replies:0
mohammad reza
  • Forum posts: 1

May 21, 2014, 10:50:36 AM via Website

hi everyone.
i made an app and i try and connect with mysql with my app with a simple php file.
here is php:

  mysql_connect($_REQUEST['host'],$_REQUEST['user'],$_REQUEST['pass']);

  mysql_select_db($_REQUEST['db']);
 mysql_query("set names 'utf8'"); 
  $q=mysql_query($_REQUEST['query']);

  while($e=mysql_fetch_assoc($q))

          $output[]=$e;

       print(json_encode($output));

mysql_close();

and in my app, i use this code :

            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            String Query = "SELECT UMail from Users WHERE UUName = '111'" ;
            nameValuePairs.add(new BasicNameValuePair("query", Query));
            nameValuePairs.add(new BasicNameValuePair("host", "localhost"));
            nameValuePairs.add(new BasicNameValuePair("user", "user"));
            nameValuePairs.add(new BasicNameValuePair("pass", "pass"));
            nameValuePairs.add(new BasicNameValuePair("db", "db"));
            try{
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost(SiteAddress + "php/Main.php");
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
                    is = entity.getContent();

            }catch(Exception e){
            }

it was working fine and everything was ok, i worked on my app about 4 month, and now its complete. i worked with this code along my app about thousands of times and everything was fine. this is a sample of how i connect to mysql.
but today my app was completed, and something wierd happend.
after i signed my app, and made it ready for publish, this code seems to have some problems. im not new in android, but this is really made me crazy, my app works 1 time, and not 10 time. i mean i have to try 10 times with my app to connect one time and with a very slow speed! i tested everything, my server is fine, i checked it and it is ok, i tried to fetch data some other way and server is ok. but this problem is really wierd! as i said, it works , it dont works, it works, it dont works and when it works it is very slow. what is wrong here?

— modified on Jun 2, 2014, 7:06:03 AM

Reply