PHP MySQL REST API for Android

PHP REST API backed up with a MySQL database is a very common schematic of an Enterprise mobile application. When the scenario requires data to be stored in a centralized manner, then this architecture should be used. Otherwise, the local database in the mobile can be used for the storage and retrieval of information.
 
In this tutorial, we are creating a PHP RESTful service to read data from a (MySQL) database table. Also, I am providing an example Android project code for invoking this RESTful service. In a previous tutorial, we have seen then basics about PHP RESTful services. I strongly recommend you to go through it before continuing this tutorial.
 
In this example, we are calling the PHP REST API from an android application. In the server side, the API service reads data from the database and sends the response in JSON format. After receiving the response, the Android application displays the row of items in a ListView by parsing the JSON data.
 
If you want to see how to handle JSON data with PHP with detailed notes and examples, then the linked article will be a perfect tutorial on this.
PHP REST API that Reads MySQL Records
We have a database table containing the list of mobile phone model names. Our REST API fetches the list of mobile names from the database and sends the response in JSON. This REST API contains three parts. These are, the REST controller, service class, and the DAO.
PHP in Website Development Era
PHP language has a unique place in website development. It was introduced at a right time when web-based business was in new trend. Over a period it became one of the popular languages for creating web applications. The reasons are,

  • simple language structure
  • unique features
  • free license.

PHP’s unique features lead to more popularity. Since 1994 when PHP development was started, we have seen the following version releases.
 
PHP Versions

Versions Key Features Description
PHP/FI (1995) ·         Form handling Perl/CGI script (PHP 1.0) introduced by Rasmus Lerdorf. The Expansion is Personal Home Page / Form Interpreter.
PHP/FI2 (1997) ·         Data conversion
·         Form data export
With slight modifications in Form Interpreter(PHP 2.0) to handle form entries.
PHP  3 – (1998) ·         PHP core is rewritten
·         PHP parser is rewritten.
·         Zend Engine is incorporated.
Language core was changed by Zeev Suraski and Andi Gutmans and PHP refers to PHP: Hypertext Preprocessor.
PHP 4 – (2000) ·         Object-Oriented support
·         External resource handling
·         Security
·         RegEx handling
With features for supporting enterprise-oriented applications.
PHP 5 – (2004) ·         Improved object model
·         PDO Support
·         Exception handling
·         XML support
PHP core was almost stabilized with this release. Later 5.X releases have slight enhancement.
PHP 7 – (2016) ·         Improved performance (twice as that of 5.6)
·         Reduced memory usage
·         The null coalescing operator (??)
·         Return and Scalar Type Declarations
·         Anonymous Classes
·         Zero cost asserts
PHP 6.0 was skipped and PHP 7 was released. There was no clear official mention on why version 6 was skipped and there are many theories floating around. You can get more information on this by going through the linked HN discussion.

 
PHP Web Constellations
PHP is one of the best choices for creating web applications. It supports advanced web constellations. It supports most of the popular databases, libraries. PHP script can be embedded with hypertext and client-side script.
With this collective integration, PHP as an open-source attracts people in web development businesses. Currently, most renowned websites are using PHP. For example, Google, Facebook, Yahoo! and more.  As per 2013 metrics made by online research agencies like Netcraft, more than 200 million websites were using PHP.
 

Categories