Member-only story

PHP Rest API Example

Bipsmedium
5 min readJan 26, 2023

--

PHP Rest API Example

Hi friends, if you are wondering how to create a PHP Rest API or perform a CRUD operation using PHP Rest API then you have come to the right place. Creation of rest API is very easy and I am going to explain it in a step-by-step process. In this example, you will learn the CRUD operation with the help of REST(Representational state transfer) API.

In a simple way, you will get the HTTP request from any kind of application or via POSTMAN and perform some action based on the type of request and return the response against that request.

Also read, Razorpay payment gateway integration in PHP

Steps to create PHP REST API

Step 1:- Establish the database connection as shown below. (dbconnect.php)

<?php
$servername='localhost';
$username="root";
$password="";
try
{
$con=new PDO("mysql:host=$servername;dbname=myproject_db",$username,$password);
$con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
//echo 'connected';
}
catch(PDOException $e)
{
echo '<br>'.$e->getMessage();
}

?>

--

--

Bipsmedium
Bipsmedium

Written by Bipsmedium

Hi, This is Biplab and I am a PHP laravel developer and other open source technologies. I am here to share my experience with the community.

No responses yet