Context:

Here we want to create a REST Web Service using PHP on a WAMPServer. The messages will be formatted as JSON entities.

A Web Service is simply some online methods you can access from any kind of code (C#, Java, Javascript, Python …).

RESTful web services are light weight, highly scalable and maintainable and are very commonly used to create APIs for web based applications.

JSON (JavaScript Object Notation) is a lightweight data-interchange format.

 

So what we want to do here is just being able to get all the users we stored in our database via a web service programmed in PHP. The client side will be a simple call from Javascript in an basic HTML page.

To start we need to create a new database and a table to store our Users which will have some fields like the FirstName and the LastName. We will do the CRUD operations (Create, Read, Update, Delete).

 

WAMP or LAMP:

First of all, you should install WAMPLAMP, or AMPPS. I will use WAMP in this example. WAMP is a PHP server which will allow you do some local tests. WAMP will provide you an Apache server for the Web server side, with MySQL and everything you need.

WampServer

phpMyAdmin:

When WAMP is installed and started and all the services as well, right click on the WAMP icon and start phpMyAdmin to access MySQL.

WAMP contextual menu - phpMyAdmin

Create the DB, table, and data:

Create your DB by clicking on the Home icon:

phpMyAdmin menu

Then click on DataBases and insert the name of your DB:

phpMyAdmin Create Database

Now we will create the User table and add some users in it:

MySQL create new table

Let’s add some users in our new table:

MySQL insert data into table

Verify that the data is there:

MySQL select all from table

Create a few more users…

Check my post about how to create the PHP service.