PHP CRUD Operation using PDO Extension

7

- Advertisement -

In the previous tutorial we learned about PDO Extension. In this tutorial we will learn CRUD operation using PDO Extension.
CRUD Stands for create, read, update and delete record in the database.

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 ‘phpcrudpdo’ . 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

Create a insert.php file for insert  record in the database . This page include a HTML form with input field where we can fill the data.

Code for insert a record in database. Once the user filled all the data and click on the submit button then data will be saved in the database using the below code:

Step 4 : Read record from the database

Create a index.php file for read all records from database.

Step 5 : Update record in  the database

Step 5.1 : 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 get a record based on the given id. Through this way we can get data autofill-data in HTML Form.

Step 5.2 : Code for update the record

Step 6 : Delete a record from the database

Place this code in the index.php file.

Download Source Code (PHP CRUD Operation using PDO Extension)
Size: 7 KB
Version: V 1.0

- Advertisement -

Leave A Reply

Your email address will not be published.

7 Comments
  1. athian deng says

    may i see crud app with two database tables

    1. Anuj Kumar says

      Yes, use Joins.

  2. isah says

    thank you sir i really enjoyed your tutorial its very awesome

Leave A Reply

Your email address will not be published.