Create PHP CRUD Rest API with Mysql

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

How to Create CRUP REST API in PHP:

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: http://www.example.com/api.php

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 http://www.example.com/api.php/users/103

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

GET http://www.example.com/api.php/users?include=comments&filter=userId,eq,103

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.

Recommended Posts For You

About Harish

I am professional web developer and blogger. Use this blog to share own api and other web development experience with you. I do accept paid work. Write to me at - [email protected]

View all posts by Harish

2 thoughts on “Create PHP CRUD Rest API with Mysql”

  1. Sir, your tutorial is very helpfull , but i am confused about getting data from multiple tables, with more than where conditions

    1. 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

Your email address will not be published. Required fields are marked *