1. Are you ready for the Galaxy S20? Here is everything we know so far!

help needed. php & mysql in application

Discussion in 'Android Lounge' started by dmastiers, Jun 22, 2013.

  1. dmastiers

    dmastiers Lurker
    Thread Starter

    I am learning android application. . Want help regarding, how to use php mysql in android app
     

    Advertisement

  2. dlhavema

    dlhavema Member

    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.
     
  3. dmastiers

    dmastiers Lurker
    Thread Starter

    I want to make app and want to store & get data from mysql
     
  4. dlhavema

    dlhavema Member

    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); "
     
    dmastiers likes this.
  5. dlhavema

    dlhavema Member

    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
     
  6. dmastiers

    dmastiers Lurker
    Thread Starter

    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 ?
     
  7. dlhavema

    dlhavema Member

    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.
     
    dmastiers likes this.
  8. dmastiers

    dmastiers Lurker
    Thread Starter

    Thanks for the help, :thumbup:
     
Loading...

Share This Page

Loading...