Best Android Studio: How to Connect Android with PHP, MySQL

Best Android Studio: How to Connect Android with PHP, MySQL
Best Android Studio: Tutorial on How to Connect Android with PHP, MySQL (PhpMyAdmin) XAMPP. Recommended to Read this post to understand more about my library: 

Please subscribe https://youtube.com/oumsaokosal?sub_confirmation=1

To connect Android with MySQL Database, you cannot do it directly. You need a Web service as a medium. In this case, we can use PHP because in PHP you can have a single of code that easily converts database data into the JSON format. You can convert it to XML as well, but many prefers JSON due to its size and performance. 

Download the lib at https://github.com/kosalgeek/generic_asynctask

Android recently changed its IDE from Eclipse-based Android Development Toolkit (ADT) to IntelliJ IDEA-based Android Studio. The big reason for that is Gradle. Gradle is a modern open source build automation system. It works better in many ways than Ant, which is used by Eclipse-based Android IDE. The change also affects some old APIs to deprecate.

In this tutorial "How to Connect Android with PHP, MySQL", l uses the new IDE, Android Studio along with the new APIs. Moreover, I created my own library that simplified the way of how to connect Android with PHP and MySQL. Before this, you had to have a private class extends AsyncTask class all the time in order to connect to the Web. The AsyncTask class works as background thread. Since Android 3.0 API 11 (Honeycombs), you are allowed to use the main thread to do a long process, such as connecting to Web. I named the lib as GenAsync.jar (Generic AsyncTask) and you can download it at https://github.com/kosalgeek/generic_asynctask. My lib hides all the complexity and all you have to do to instantiate the PostResponseAsyncTask class and pass a POST data as a second argument of the constructor. You call the execute() method and provide the URL that you want to pass the data to. Finally, you can receive the data by processFinish() method. This course guides how to create a database and a table in MySQL and create PHP pages.

Check out the latest articles on Android Phone at:

Subscribe. Like. Share. Comment.

Oum Saokosal

Photo Credit: 
The photo (https://www.flickr.com/photos/janitors/21027307169) used in my video cover is copyright (c) by Kārlis Dambrāns (https://www.flickr.com/photos/janitors/) made it available under Creative Commons (https://creativecommons.org/licenses/by/2.0/).

RRelated Posts

REST API concepts and examples

This video introduces the viewer to some API concepts by making example calls to Facebook's Graph API, Google Maps' API, Instagram's Media Search API, and Twitter's Status Update API. /**********

11 Cool Websites Everyone Should Know!

Did you know about all these cool websites? More Top Lists ▶ https://www.youtube.com/playlist?list=PLFr3c472Vstw-sCvBrlRTelW3ULg1-w3n Subscribe Here ▶

This Smartphone Changes Everything...

The Oppo Find X may be our best glimpse into our collective smartphone future. Smartphones are set to become completely bezel-less and the Oppo Find X is the first retail example I've seen. The Find


  • مريم عامر
    If I have username, password for php server firewall what I must write in android code?
  • Usman Shahzad
    Thanks a lot Sir.. you are awesome...! <3
  • C89-HD
    Can i read json From php with volley. And what IS thé best solution volley or Asynctask ?????? Thanks
  • manassé bitemo
    how can I access received sms and transfer them to the database with your method
  • umair naveed
    Great Work!
  • John Levi Peralta
    Sir I have problem log in for android its Log in Failed!

    This is the problem can you Help me plss..

    W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
    I/Choreographer: Skipped 117 frames! The application may be doing too much work on its main thread.
    D/EGL_emulation: eglMakeCurrent: 0xa4477280: ver 2 0
    D/EGL_emulation: eglMakeCurrent: 0xa4477280: ver 2 0
    I/Choreographer: Skipped 65 frames! The application may be doing too much work on its main thread.
    D/EGL_emulation: eglMakeCurrent: 0xa4477280: ver 2 0
    D/EGL_emulation: eglMakeCurrent: 0xa4477280: ver 2 0
    D/EGL_emulation: eglMakeCurrent: 0xa4477280: ver 2 0
    D/PostResponseAsyncTask: IOException Error: java.net.SocketTimeoutException: failed to connect to / (port 80) after 15000ms
    D/EGL_emulation: eglMakeCurrent: 0xa4477280: ver 2 0
    D/EGL_emulation: eglMakeCurrent: 0xa4477280: ver 2 0
    D/EGL_emulation: eglMakeCurrent: 0xa4477280: ver 2 0
    D/EGL_emulation: eglMakeCurrent: 0xa4477280: ver 2 0
    D/EGL_emulation: eglMakeCurrent: 0xa4477280: ver 2 0
  • rhea butala
    How can i read data from database if login id and pasaword are valid and display it in the next activity in ?
  • khaing pho
    Thank for your sharing the useful tutorial!
  • Sandeep Mathur
    sir when sending post data to my local server then the result in processFinish is empty.....help me
  • Archana Soyjaudah
    Thank you Sir! :-)
  • Rushabh Buch
    Can we use the same code if we want to test in on a real android device and not on emulator
  • Waleed Ahmad
    Hi Oum, can i connect livePHPMYSQL with webview
  • Bhargav Mehta
    Pls remove noise it's terrible. Upload video again
  • ҭђἔ łᾄṩҭ ṩἔмἷƈὄłὄᾗ
    awesoOoOoOome great thx!
  • Bosch Pharma
    GOOD TUTORIAL.. i want connect android with oracle database. how can i do.. can u plz help me ....
  • Jenish Parmar
    error in line no 12 solve pleash
  • Jennifer Flynn
    When I create an instance of PostResponseAsyncTask it says it is deprecated . PostResponseAsyncTask task = new PostResponseAsyncTask(this); is what i typed. Error is: it is deprecated. Can someone tell me how to fix this please
  • Code Man
    how can i get your source code ?
  • patel vaibhavee
    Sir apne xmap me htdocs use kya vese ham wampserver me kya use kre ne ge?
  • Code Man
    what is the different between using jdbc and php connection and please which one is better ?
  • Adenilson Silva
    hello, I'm having problem with php error, isset, could you help me?
    Parse error: syntax error, unexpected T_ISSET, expecting T_STRING or T_VARIABLE or '$' in
  • Adenilson Silva
    ola, estou com problema com erro no php, isset, poderia me ajudar?

    Parse error: syntax error, unexpected T_ISSET, expecting T_STRING or T_VARIABLE or '$' in
  • Anurag Singh
    sir i am facing with a problem when i run my login.php it,s show a error "Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\client\login.php on line 36"
    and my code is this
    if( isset($_POST['txtUsername']) && isset($_POST['txtPassword']) ) {
    $username = $_POST['txtUsername'];
    $password = $_POST['txtPassword'];

    $query = "SELECT username, password FROM tbl_client ".
    " WHERE username = '$username' AND password = '$password'";

    $result = mysqli_query($conn, $query);

    if($result->num_rows > 0){
    if(isset($_POST['mobile']) && $_POST['mobile'] == "android"){
    echo "success";

    echo "Login Failed <br/>";


    <h1>Login Example|<a href=”http://www.google.com”>Anurag</a></h1>
    <form action="<?PHP $_PHP_SELF ?>" method="post">
    Username <input type="text" name="txtUsername" value="" /><br/>
    Password <input type="password" name="txtPassword" value="" /><br/>
    <input type="submit" name="btnSubmit" value="Login"/>
  • Umer farooq
    That was really helpful but i can't manage to configure out your php script, it dos't event work on web for test, 2nd is i only get the a little long toast not any rough php/html data.
    what i'm supposed to do to get rid of this.
  • Andre Heuer
    I don't get my light bulb red, but it is okay, if i just implement your class?
  • Daniela Radcliffe
    Hi Do you have a tutorial to connect Android Studio with postgresql?
    Thank you so much. I really got your php db connection helpful. Can I get video for signup.
  • Madhuri Gurav
    I have problems client is not ready yet please give me solution
  • Mm Gho
    how to make app to store data not for log in ...like users save their names and their age then all users can search for a specific age to get all the names
  • KDV Shared
    thanx,, its simple...
  • Areeba Shaikh
    i am getting my html code as response in log...but without success or something liked failed..
    just the form that i created for php :( can anyone help me please
  • Учитель Литературы
    A? My names is... A? My names.... TUtutu
  • Anurag Biswas
    when i try to enter parameters inside PostResponseAsyncTask()
    it strikes the PostResponseAsyncTask() and says it has been deprecated.
  • M G Shahriar
    i want to implement website login registration in Android app?? how i do that one database for web and mobile
  • Kirbi Timur Nomas
    gimana caranya buat koneksikan aplikasi android dgnn codeigniter sql tapi bukan localhost pak, via internet caranya gmn yah ?
  • Christian jay Bringino
    Hi, I need help about the GenAsync library.. when I type PostResponseAsyncTask task = new PostResponseAsyncTask(this); <--- it says that the new "PostResponseAsyncTask" is deprecated.. I don't know what to do next... I need help
  • Che Mohamad Firdaus Che Saidi
    Subscribed you ! Your videos help me a lot. Thank you 😊
  • Anyone can
    thankyou very much
  • Sally Morris
    I cant see the blog on the website and therefore i cant get the code
  • mugumya martin
    The database doesn't seem to connect to my device
    I'm using Leapdroid as my emulator
  • Temper Damodar Chowdary
    please give me your mail id
  • Temper Damodar Chowdary
    hi sir Thanks a lot ..............its very easy to understand ....im trying from 25days but I didn't ....today I got the result thanks a lot
    PostResponseAsyncTask task = new PostResponseAsyncTask(this,postData);

    postData is came in red again sir! what to do now???

    i selected the red bulb and implemented, the error was gone , but after running the app, and after giving username and password after clicking login , it says unfortunately stopped
    i used http://localhost/client/login.php to run the app in my android mobile phn..
    please help sir....
    PostResponseAsyncTask task = new PostResponseAsyncTask(this);

    while touching "this" im getting yellow light, but not red light! please help me sir..!!!
  • Areeba Shaikh
    ohh great!!! i was trying to do this since last one month...sir u are great :) (Y)
  • Fajar Ramadhan
    i want ask sir .. if i already download getasynctask .. and i installing with cmd (win7) , what next step ?

    cause my coding (login.php) is error ... preview is japanase or chinnese languange ..

    but if i just take html coding .. its normal (work)

    please give the solution
  • kuldeep negi
    please can u tell me how to access a specific function of web api inside my android program?

    then it should fetch the data for me according to api.

    how can i use it un my program?
  • Razor Dkesh
    Hello sir thanx for great tutorial . and i connect to database successfully but the problem is that when i access data base from outside network (other wifi) then it cannot be accessed please help me??
  • Nesrine Kréchiche
    by using the button ,html code appears as you but without "success " of php
    is the application connected or no if no what is the solution !??
  • Mian Kamran Manzoor
    hello sir i'm testing my app on my cell phone, so what should be the "localhost" replacement for me ? kindly help.. thanks