PHP CRUD Operations using PHP OOP and MYSQL

CRUD means Create, Read, Update and delete. In this tutorial I will explain how to perform crud operation  using PHP OOP 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.21 KB
Version: V 1.0

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.

Recommended Tutorials for you

You may also like...