Skip to main content

PHP PDO OOP CRUD Class with Bootstrap

In this Article we are going to learn about PHP PDO class, which can perform Create, Read, Update and Delete (CRUD). If you don’t know about PDO please refer to the PDO reference link before heading to this article.


File Structure

Our File Structure will be as following:

File structure

Database Schema

Create Database named pdocrud and import the following table. Use following mysql query which will create a User table with 4 fields. id, firstname , lastname, and email.


In the file structure you can see the config.php, which is our configuration file. This file is responsible for our database connection, and we also include our CRUD class here like include_once 'class.php-crud.php'; use the following code for the config.php file.

CRUD Class

This is our main file, which contain all our Create, Read, Update and Delete operation. You will also find pagination and View class here.

Index File

This is our landing file which includes our header and footer file we will not go in deep with header and footer file as it just normal files with header and footer content. In the main section we have a bootstrap table inside index.php which fetching data from database using php pdo CRUD class.

Add file

Now create one file named add.php this file will have a form for user to fill up and the data will be added to the database using CRUD class. This form will show Success and error message after submitting, that shows users the record actually inserted, or not.

Add view

Edit file

Now Create another file named it edit.php, This file will responsible to update data that we have added throw the add.php form. Here we used CRUD class to Update user’s information to our database.

Edit view

Delete file

This file contains code, which will delete the record, but before deleting record it will confirm once with the user.

Delete view



You can download a source code from the above link. I would like to thanks codingcage for the reference. Let me know your review and suggestion on this tutorial by posting a comment below.












Hardik Joshi

Hardik Joshi is Founder, Developer and Writer at, He loves to write usable code for the Web and other digital sources.