PHP CRUD Operation using Stored Procedure


- Advertisement -

In previous tutorial, we learned about stored procedure in PHP. In this tutorial, we will learn CRURD operation using Stored Procedure.

File Structure for CRUD Operation

dbconfig.php-  used for database connection
tblusers.sql–  Contain the structure of the database table
insert.php- used for add a record in the database
index.php–  Used for read the record from database .
update.php– Used for updating a record.

Step 1– Create a database

Open browser type http://localhost/phpmyadmin, create a database named ‘spcruddb’ . After creating database run the SQL script or import the SQL file.

Step 2– Create a database connection file (dbconfig.php)

create a dbconfig.php file and place the code given below :

Step 3 : Insert a record in database

Step3.1 Create an insert.php file for insert record in the database. This page includes an HTML form with an input field where we can fill the data.

Step 3.2: Create a stored procedure for data insertion “sp_insert”

Step 3.3: PHP Code for Data Insertion

Here is the full code that we have written for data insertion (insert.php)

Step 4 : Read record from the database

Create a stored procedure (sp_read) for read data

Now, create a index.php file for read all records from database.

Step 5 : Update record in  the database

Step 5.1 : Create a stored procedure (sp_sp_readarow) for read data of a particular row

Step 5.2 : Get  data in  HTML From 

create update.php file. For updating a record we have to get the row id of that record and store in $id. We access the $_GET[‘id’] variable to do it.
Code for gets a record based on the given id. Through this way, we can get data autofill-data in HTML Form.

Step 5.3 : Create a stored procedure (sp_update) for for update a record

Step 5.4 : Code for update the record

Here is the full code that we have written for data updation (update.php)

Step 6 : Delete a record from the database

Step 6.1: create a stored procedure(sp_delete) for delete a particular record

Step 6.1: PHP Code for data deletion

Place this code in the index.php file.

View Demo———————————————————

Source Code (PHP CRUD Operation using Stored Procedure)
Size: 6.47 KB
Version: V 1.0

- Advertisement -

Leave A Reply

Your email address will not be published.