2013-03-19 63 views
0

我已經使用本地主機上的xampp連接數據庫與phpliteadmin。現在我必須從本地主機檢索數據並更新它。所以任何1都可以幫助我解決這個問題。Android:如何檢索從phpliteadmin到android應用程序的數據..?

+0

M沒有得到如何啓動?你有沒有任何示例代碼? – Jaswant 2013-03-19 10:15:56

+0

然後閱讀此http://moinur-rahman.blogspot.com/2012/02/connection-between-android-app-and.html和這個http://stackoverflow.com/questions/8415467/connecting-to-mysql -database-using-php-from-an-android-device – Kira 2013-03-19 10:22:06

+0

thnxs alots .... – Jaswant 2013-03-19 13:01:19

回答

2

確定我有一些數據發送到本地主機的功能,並從那裏 使用這種方法進行通信獲取一些數據: -

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) { 

    } 
} 

,你可以使用這個PHP代碼來發送和檢索值: -

<?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); 


?> 
相關問題