0

I have connected database with phpliteadmin using xampp on localhost. Now I have to retrieve data from localhost and also to update it.. So any 1 can help me out from this problem..??

  • M not getting how to start?? do u have any sample code? – Jaswant Mar 19 '13 at 10:15
  • then read this http://moinur-rahman.blogspot.com/2012/02/connection-between-android-app-and.html and this http://stackoverflow.com/questions/8415467/connecting-to-mysql-database-using-php-from-an-android-device – Kira Mar 19 '13 at 10:22

1 Answers1

2

ok i have a function that sends some data to your local host and retrieve some data from there use this method for communication :-

public void postData() throws Exception {
    postData=et.getText().toString(); //some value

    HttpClient httpclient = new DefaultHttpClient(); // connection
    HttpPost httppost = new HttpPost("http://192.168.1.21/default.php"); //ip of your local host and php file!

    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("msg", ""+str));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8));
        ResponseHandler<String> responseHandler=new BasicResponseHandler(); // to get the response printed there
        String responseBody = httpclient.execute(httppost, responseHandler); // here we are recieving values.

        Toast.makeText(this, responseBody, Toast.LENGTH_LONG).show();
    } catch (ClientProtocolException e) {
            e.printStackTrace();
    } catch (IOException e) {

    }
}

and you can use this php coding to send and retrieve values :-

<?php
include ('MCrypt.php'); //this my encryption example
$thename=$_POST["msg"]; //get values from there using post and "msg" must be same on both side!
$mcrypt = new MCrypt();
$decrypted = $mcrypt->decrypt($thename);

echo("Your Encrypted String:--".$thename."\n");  // this line will be sent to android and will be recived in String Response;
echo("Your Decrypted String:--".$decrypted);


?>
Cyph3rCod3r
  • 1,978
  • 23
  • 33