In my previous post I was talking about how to install WAMP and create your DataBase. Here we will create a RESTfull web service with PHP.

We created our User table with some users in it. Now we want to get this user list in a “universal” way. It means any kind of code could potentially access our web service via JSON messages and the standard HTTP protocol.

Create the PHP REST service

When you installed WAMP, it created a WWW folder in the WAMP folder path (for example: C:\wamp\www). Create a new file called DbUsersApi.php for example and another one called DbSettings.php and open them with Notepad, Notepad++, Sublime Text or another text editor.

Paste this PHP code in DbSettings.php:

Save it and open DbUsersApi.php and past this:

Now if you go in a web browser and you put this address:

http://localhost/DbUsersApi.php?action=get_user_list

Then you should see the JSON result of your users in the database.

See my post about how to consume this web service with Javascript.