• 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

do you want to use php and mysql to support your android app, or php and mysql inside of your android app? the first one is totally doable, the 2nd one is not.
 
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); "
 
the forum changed my link but its just an example of how to call the get contact method...

www-example-com/getcontact.php?ID=10
 
I have created php/mysql script that returns data by id, like index.php?id=523

And want to use it into android app

Do you any example or help of how to use json or google json ?
 
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.
 
Back
Top Bottom