0% found this document useful (0 votes)
192 views3 pages

Rest API Crud Using PHP - Phppot

Uploaded by

Asma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views3 pages

Rest API Crud Using PHP - Phppot

Uploaded by

Asma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

04/01/2021 REST API CRUD using PHP - Phppot

helping build websites Shop Services Testimonials Blog About Con

eCommerce REST API CRUD using PHP Hi, I’m Vincy. I help build websites
Components Last modified on April 4th, 2017. and I’m available for freelance work.
Files
In this tutorial, we are going to create a RESTful web service in PHP for [email protected]
UI performing the CRUD operations. In previous tutorials, we have seen examples
Performance for MySQL CRUD and for creating a RESTful web service using PHP. In this
Contact Form - Iris
tutorial which is part of the REST API series, let us learn about how to provide a
Framework
simple REST API for CRUD (Create, Read, Update and Delete) operations. We
PHP will not be using any framework as dependencies, the complete implementation
Learn PHP will be using plain core PHP.
PHP Introduction
Let us see about the conventions I have used in this example. The READ and
PHP Basics
DELETE actions are executed by sending the action keyword in the URL and is
Contact Form
parsed by the GET method. In the REST Search tutorial, we have used this
Comments System
method to send the search keyword as a query parameter in the URL to be
Types, Variables &
Operators searched. The ADD and UPDATE actions are called by sending the request
PHP Strings data using POST method.
PHP Arrays
PHP Functions
PHP OOPS
“She is cooperative and able to quickly
PHP Forms
understand our needs behind different
Advanced features. We kept the estimated budget a
PHP AJAX within the assumed timeline. ...” read mo
RESTful API
Marcin Bialy, Grandmetric, Poland
PHP RESTful Web
Service API - Part 1 -
Introduction with Step-
by-step Example
PHP MySQL REST API
for Android
REST API CRUD
using PHP
REST API Search
Implementation in PHP
PHP Databases
PHP Sessions and
Cookies
REST API Create and Update Implementation
Error and Exception
Handling
CREATE and UPDATE requests are sent with the posted values. The UPDATE
File Upload
Files and Directories
request URL will contain the id of a particular row to be updated.
PHP Date Time
After receiving this request, the REST CRUD service will call the domain class
PHP XML
to perform the database insert. The domain class will generate insert query
PHP Code Samples
using the posted values. The following figure shows how to POST data for the
Library
CREATE or UPDATE request.
More PHP
PHP Freelancer I am using the “Advanced REST Client” Google Chrome plugin to test the REST
APIs.

https://phppot.com/php/rest-api-crud-using-php/ 1/3
04/01/2021 REST API CRUD using PHP - Phppot

Delete using REST API


The DELETE request URL will be same as the EDIT URL. The record ID to be
deleted should be passed in the URL After delete, the API response will be like
as shown below.

Domain Class used for this CRUD Example


The following code shows the Mobile domain class that contains the function for
performing the database CRUD operations. These functions are called by the
REST handler class based on the request sent from the client. The
domain class CRUD functions will return array response to the REST handler
which is encoded as JSON format.

https://phppot.com/php/rest-api-crud-using-php/ 2/3
04/01/2021 REST API CRUD using PHP - Phppot
<?php
require_once("dbcontroller.php");
/*
A domain Class to demonstrate RESTful web services
*/
Class Mobile {
private $mobiles = array();
public function getAllMobile(){
if(isset($_GET['name'])){
$name = $_GET['name'];
$query = 'SELECT * FROM tbl_mobile WHERE name LIKE "%' .$na
} else {
$query = 'SELECT * FROM tbl_mobile';
}
$dbcontroller = new DBController();
$this->mobiles = $dbcontroller->executeSelectQuery($query);
return $this->mobiles;
}

public function addMobile(){


if(isset($_POST['name'])){
$name = $_POST['name'];
$model = '';
$color = '';
if(isset($_POST['model'])){
$model = $ POST['model'];

download

Popular Articles
★ PHP RESTful Web Service API – Part 1 – Introduction with Step-by-step Example
★ REST API Search Implementation in PHP
★ PHP MySQL REST API for Android

Search articles

↑ Back to Top

Looking for a freelance web developer?


Do you want to build a modern, lightweight, responsive website and launch quickly? Contact Me

Blog subscription:

Enter your email here Subscribe

Shop

FAQ Support Policy Refund Policy Licenses


Terms of Service Privacy Policy Cookie Policy © 2020 Phppot

https://phppot.com/php/rest-api-crud-using-php/ 3/3

You might also like