2013-03-19 87 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); 


?> 
相关问题