Connecting to a remote mysql database using php and Android?
Sabtu, 04 Mei 2013
0
komentar
Look at the varaible name inside the $_POST. Make sure that you use the same variable name in the Android side also. It is also case sensitive. Here I am echoing back any value that is sending from the Android side.You can do anything with it in the server side. Here I am just echoing it back.You can simply insert it into a database and echo something else. Anything you echo will be received by the Android Our Server side code is completeNow we switch on to the Android side. This is the code that connects with the server.
$val = $_POST['my_val'];
echo $val;
If you are working on LocalHost use url "http://10.0.0.2/your_folder_address.php"OK Done. You have successfully connected to a remote server. Check your LogCat for the value from the server Make sure you have internet connection before doing this, otherwise exception will be thrown. By this way you can send any number of variables from the Android side to the PHP side but make sure that both have the same name (case sensitive).
Thread thread = new Thread()
{
@Override public void run()
{
try
{
httpclient=new DefaultHttpClient();
httppost= new HttpPost("your url");
}
}
// make sure the url is correct.
//add your data
nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("my_val","my Test value from the Android Side"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//Execute HTTP Post Request response=httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
System.out.println("Response : " + response);
}
catch(Exception e)
{
System.out.println("Exception : " + e.getMessage());
}
}
};
thread.start();
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Connecting to a remote mysql database using php and Android?
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke https://androidpopuler.blogspot.com/2013/05/connecting-to-remote-mysql-database.html. Terima kasih sudah singgah membaca artikel ini.Ditulis oleh Unknown
Rating Blog 5 dari 5
0 komentar:
Posting Komentar