PDO

PHP CRUD Operation using PDO Extension

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: 5.65 KB
Version: V 1.0

 

About the author

Anuj kumar

I'm Anuj kumar a web developer with 4+ year experience .I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to is provide php , jquery , mysql , phpoops and other web development tutorials. I am trying best effort to make PHPGurukul useful for every single moment spend on this website. If you think this website is useful to visit please share with your friend and buddies.