• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

help needed. php & mysql in application

well they just redesigned it but php.net is a great site for learning how to do things in PHP. basically you have to design what you want to view/access/update in the MySQL database and layout that first. Then you need to expose php scripts that can perform that functionality, ( a simple way would be a file called "getcontact.php" which when given an ID, would return all the details about a given contact for example... )

Then you need to create Android code to make a HTTPRequest to call your page Example Domain for example.... and then process the return, JSON is a great simple format, and using Google Gson you can map from Json to Java Objects extremely easily. and php can output json as easily as calling " echo json_encode($array); "
 
  • Like
Reactions: dmastiers
Upvote 0
Http get request in Android - Stack Overflow has a good example of how to get it to your android app.

the method readStream(inputstream) they reference should process the input stream coming from your PHP page.

Gson: https://sites.google.com/site/gson/gson-user-guide

then send it to something like this:

[HIGH]
String json = "";// this is the content read in from the input stream.
JsonParser parser = new JsonParser();
JsonObject jsonObj = parser.parse(json).getAsJsonObject();
String username = jsonObj.get("username").getAsString();
//use username for whatever you want...
[/HIGH]

then use the jsonObj variable as a regular java object and do what you need to with the result.
 
  • Like
Reactions: dmastiers
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones