PHP CRUD Operations using PHP OOP and MYSQL


- Advertisement -

CRUD means Create, Read, Update and delete. In this tutorial, I will explain how to perform crud operation using PHP OOPs and MySQL.
Create a
database   oopscrud.

Now create an SQL table tblusers inside this database. Structure of tblusers  table

function.php is the main file which will handle the database connection, insert, read, update and delete.

DB_con is the constructor function which will create localhost connection and database selection.
public function insert() function have some parameter which will accepts inputs from html form.
public function fetchdata() function read all the data from tblusers table.
public function fetchonerecord() function have one parameter userid. On the basis of the userid this function will read the data.
public function update() function have some parameter with user id which will accepts inputs from html form to update the record.
public function delete() function have one parameter rid(row id). On the basis of the rid(row id) this function will delete the data.

Create: Data Insertion (insert.php)

Create a html form

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:

Read : Fetch the Data(index.php)

UPDATE : Data Updation(unpdate.php )
Get the data in HTML form .
Code for get a record based on the given id. Through this way we can get data autofill-data in HTML Form.

Code for update the record

DELETE : Record Deletion

Delete a record from the database

CRUD Script using PHP OOP and MYSQL
Size: 5.46 KB
Version: V 1.0

- Advertisement -

Leave A Reply

Your email address will not be published.

  1. gin says

    Insertion query part is not working for me

    1. Anuj Kumar says

      Share your error at

  2. hussam almoussa says

    Wonderful code,working perfect Thanks

Leave A Reply

Your email address will not be published.