{"id":3103,"date":"2022-01-06T06:28:17","date_gmt":"2022-01-06T06:28:17","guid":{"rendered":"https:\/\/externlabs.com\/blogs\/?p=3103"},"modified":"2023-09-05T11:19:34","modified_gmt":"2023-09-05T05:49:34","slug":"php-for-android","status":"publish","type":"post","link":"https:\/\/externlabs.com\/blogs\/php-for-android\/","title":{"rendered":"How to Use PHP for Android App Development"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">You might not hear or not that you can use PHP for your Android App Development. We can use PHP as the back-end for our Android Applications, and trust me they work flawlessly with each other. Any Android app that needs account log-in and registration can efficiently utilize PHP on its back-end.<\/p><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_63 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Page Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/externlabs.com\/blogs\/php-for-android\/#PHP_for_Android\" title=\"PHP for Android\">PHP for Android<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/externlabs.com\/blogs\/php-for-android\/#PHP_for_Android_App_Back-end\" title=\"PHP for Android App Back-end\">PHP for Android App Back-end<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/externlabs.com\/blogs\/php-for-android\/#Login_Registration_Interface\" title=\"Login Registration Interface\">Login Registration Interface<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/externlabs.com\/blogs\/php-for-android\/#XAMPP_Server_Set-up\" title=\"XAMPP Server Set-up\">XAMPP Server Set-up<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/externlabs.com\/blogs\/php-for-android\/#Database_Set-Up\" title=\"Database Set-Up\">Database Set-Up<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/externlabs.com\/blogs\/php-for-android\/#Create_DataBase\" title=\"Create DataBase\">Create DataBase<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/externlabs.com\/blogs\/php-for-android\/#Create_Table\" title=\"Create Table\">Create Table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/externlabs.com\/blogs\/php-for-android\/#Insert_values_to_Tables\" title=\"Insert values to Tables\">Insert values to Tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/externlabs.com\/blogs\/php-for-android\/#Get_Post_method\" title=\"Get &amp; Post method\">Get &amp; Post method<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/externlabs.com\/blogs\/php-for-android\/#Connect_PHP_to_MySQL_database\" title=\"Connect PHP to MySQL database\">Connect PHP to MySQL database<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/externlabs.com\/blogs\/php-for-android\/#Android_Login_Registration\" title=\"Android Login &amp; Registration\">Android Login &amp; Registration<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<p class=\"wp-block-paragraph\">Almost every Android applications need essential user data, for that they have to integrate log-in and registration options that provide user\u2019s contact and other details to the back-end. So, let\u2019s explore how you can use PHP on your backend of the Android Application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Essentially we have to make a log-in and register interface for the android application so we will set up a local PHP server and MySQL database to build PHP Web Development.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"PHP_for_Android\"><\/span>PHP for Android<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP is best known for its incredible and versatile use in Web Development but we can utilize it in many more ways. Today, We are going to use PHP in android app development and how will it going to benefit us. PHP&#8217;s best use in Android Applications is in the back-end and database. We are going to guide you through setting up a local server and MySQL Database that will help you in managing user registration and other details.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"PHP_for_Android_App_Back-end\"><\/span>PHP for Android App Back-end<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s get into details about how to use PHP on the back-end of your Android Application. Follow our simple step-by-step guide to set PHP local server and MySQL database and connect them to the back-end of your Android application.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Login_Registration_Interface\"><\/span>Login Registration Interface<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Firstly, we are going to create a back-end web server for the android application. You can use any operating system and use XAMPP. It will help you set up a local Apache Web Server and MySQL database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"XAMPP_Server_Set-up\"><\/span>XAMPP Server Set-up<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Installing XAMPP is pretty easy, just make it google, and then you can get a one-click installation file for any operating system from <a href=\"https:\/\/www.apachefriends.org\/index.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">their website<\/a>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2022\/01\/xampp-logo.png\" alt=\"php for android\" class=\"lazyload_inited wp-image-3107\" style=\"width:625px;height:350px\" width=\"625\" height=\"350\" srcset=\"https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2022\/01\/xampp-logo.png 625w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2022\/01\/xampp-logo-300x168.png 300w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">After successful installation, you can test it by running or calling http:\/\/localhost. It will open a new screen and check admin by http:\/\/localhost\/phpmyadmin.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can create a folder there like test and copy your files or test files and you can open them via http:\/\/localhost\/test_android\/test.php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, our local server is good to go and we need to set up the database and for PHP MySQL is the best.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Database_Set-Up\"><\/span>Database Set-Up<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To set up call phpMyAdmin by visiting http:\/\/localhost\/phpmyadmin and selecting the database tab from the left top header.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Give it a name you like or your project name and create the database. It can be seen and accessed from the left slide bar. Now create a User table for your App.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the given codes to create and set the MySQL database.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"900\" height=\"400\" src=\"https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2022\/01\/MySQL.jpeg\" alt=\"\" class=\"wp-image-3108\" srcset=\"https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2022\/01\/MySQL.jpeg 900w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2022\/01\/MySQL-300x133.jpeg 300w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2022\/01\/MySQL-768x341.jpeg 768w, https:\/\/externlabs.com\/blogs\/wp-content\/uploads\/2022\/01\/MySQL-696x309.jpeg 696w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure>\n<\/div>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_DataBase\"><\/span>Create DataBase<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">First, you have to create the database and it can be done via the above-mentioned method or you can simply run this code and it will create a database in a single click.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n   $con=mysqli_connect(\"example.com\",\"username\",\"password\");\n   $sql=\"CREATE DATABASE my_db\";\n   if (mysqli_query($con,$sql)) {\n      echo \"Database my_db created successfully\";\n   }\n?&gt;\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_Table\"><\/span>Create Table<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After creating the database you have to create a user table which can be done by running this code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n   $con=mysqli_connect(\"example.com\",\"username\",\"password\",\"my_db\");\n   $sql=\"CREATE TABLE table1(Username CHAR(30),Password CHAR(30),Role CHAR(30))\";\n   if (mysqli_query($con,$sql)) {\n      echo \"Table have been created successfully\";\n   }\n?&gt;\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Insert_values_to_Tables\"><\/span>Insert values to Tables<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Tables are useless until they have some values in them. Use this code to add values to your user tables in your database.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n   $con=mysqli_connect(\"example.com\",\"username\",\"password\",\"my_db\");\n   $sql=\"INSERT INTO table1 (FirstName, LastName, Age) VALUES ('admin', 'admin','adminstrator')\";\n   if (mysqli_query($con,$sql)) {\n      echo \"Values have been inserted successfully\";\n   }\n?&gt;\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Get_Post_method\"><\/span>Get &amp; Post method<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">We can insert values by $_Get and $_Post commends.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n   $con=mysqli_connect(\"example.com\",\"username\",\"password\",\"database name\");\n\n   if (mysqli_connect_errno($con)) {\n      echo \"Failed to connect to MySQL: \" . mysqli_connect_error();\n   }\n\n   $username = $_GET&#91;'username'];\n   $password = $_GET&#91;'password'];\n   $result = mysqli_query($con,\"SELECT Role FROM table1 where Username='$username' \n      and Password='$password'\");\n   $row = mysqli_fetch_array($result);\n   $data = $row&#91;0];\n\n   if($data){\n      echo $data;\n   }\n   mysqli_close($con);\n?&gt;\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This part is a bit tricky, We suggest you <a href=\"https:\/\/externlabs.com\/hire-php-developer.php\" target=\"_blank\" rel=\"noreferrer noopener\">Hire PHP Developer<\/a> to help you with this. They will make this technical part easier for you can go back to your android app development.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Connect_PHP_to_MySQL_database\"><\/span>Connect PHP to MySQL database<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To connect PHP to the database you will need to input three values which are Hostname, MySQL username, and password.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To check your connection run http:\/\/localhost\/test_and\/test-connect.php . it will give you an output, if not then restart the XAMPP.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Android_Login_Registration\"><\/span>Android Login &amp; Registration<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now we successfully connected MySQL and backend; You will need to build a sign-in\/login and registration interface.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test some random users by entering random users to the tables to get the idea of our work and you are good to use this database and back-end made on PHP. All you need is to build the login and registration part on your android application. or you can <a href=\"https:\/\/externlabs.com\/hire-mobile-developer.php\" target=\"_blank\" rel=\"noreferrer noopener\">Hire Mobile App Developers<\/a> to get that done professionally. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>You might not hear or not that you can use PHP for your Android App Development. We can use PHP as the back-end for our Android Applications, and trust me they work flawlessly with each other. Any Android app that needs account log-in and registration can efficiently utilize PHP on its back-end. Almost every Android&hellip;<\/p>\n","protected":false},"author":2,"featured_media":3741,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[179],"tags":[195,196,168,170],"class_list":["post-3103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mobile-app-development","tag-android-app-development","tag-php-development","tag-software-development","tag-web-development"],"_links":{"self":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/posts\/3103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/comments?post=3103"}],"version-history":[{"count":0,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/posts\/3103\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/media\/3741"}],"wp:attachment":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/media?parent=3103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/categories?post=3103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/tags?post=3103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}