Using CRUD Restful Php Api Service with Mysql Database Table

In this post we will explain that how to Add, List, Update, Delete and Find Relation with user database table using CRUD Rest api in php. It can be used in stand alone mode. Just place the api.php file on your sever directory.

Let we explain the procedure step by step:

Step 1: First create a table with the name of “users” in your database.

Step 2: Now upload the api.php file on your server or directory.

Step 3: Now configure the api.php file with your database information. Update below information in that file.

Step 4: After configure the file, you can use benefit through this URL:

Step 5: Now you can use crup rest api to get user database table data via GET method.

GET http://localhost/api.php/users

Use below php curl example to GET the users info:

This api call give you result in json format.

Step 6: Similarly you can use POST method to Add new user in table. PUT method to update the table, for update call you need to pass json object data as parameter. Let me show you an example for it.

Step 7: To delete a record from user table use DELETE

Step 8: To find the relation between two database table use this method


Create an another table with the name of comments and find the relation between them on the basis of userId column.

Their is also way to use crud rest api for Microsoft SQL Server and PostgreSQl 9. Just uncomment the SQL server info at the end of api.php file and configure your database details. Than use this api to manipulate the data.

2 thoughts on “Using CRUD Restful Php Api Service with Mysql Database Table

    • Hi, i did not try this with multiple tables data. I think you can make multiple api calls for them and merge the table api data. Get each table data via single api call.

Leave a Comment