CRUD operation in CodeIgniter

In this tutorial we will learn aboout CRUD operation in CodeIgniter. CRUD Stands for create, read, update and delete record in the database.

SQL table tblusers structure used in this CRUD Operation.

1.Create a database then configure your db credential in application/database.php

2. Load libraries and helpers in application/autoload.php that used in this CRUD operation.

  • Database library used for database related queries
  • Session library  used for display success / error message using flashdata.
  • form_validation library used for form validation rules.
  • Html Helper for used for link_tag
  • form helper used for form
  • url helper used for base_url.

For Data insertion (Create Operation)

Create a view for data insertion (insert.php) inside application/views

Create a controller for data insertion (Insert.php) inside application/controller. Set the validation rules in this controller.

Create a model (Insert_Model.php) inside application/model.

For Data Fetching (Read Operation)

Create a model (Read_Model.php inside application/models) for reading data from database using Active Records .

Now create a controller (Read.php) inside application/controller.

Create a view(read.php inside application/views) for showing data.

For Data Updation (Update Operation)

In previous operation we fetched all data from database.  Now whenever user will click on the edit button row id passed to controller on the basis of that row id we will fetch and update the data.

First we will fetch the particular row data then update . We already created a controller Read.php now add a  function with parameter “getdetails($uid)”  in this controller for fetch particular record.

Now we will add a new function “getuserdetail($uid)” in Read_Model.php for fetching particular row data.

Create a view for data updation(update.php) inside application/views.

Now add a function “updatedetails” in Insert.php for data updation and set validation rules in this controller.

After this add a new function “updatedetails” in Insert_Model.php for data updation.

For Data Deletion (Delete Operation)

Create a controller (Delete.php) inside application/contollers.

Now create a model for data deletion(Delete_Model.php) inside application/model.

View Demo ——————————————————-

View Demo

How to run this script

  1. Download the zip file .
  2. Extract the zip and copy cicrud folder
  3. Paste in root directory(For xampp htdocs and for wamp www)
  4. Open your browser put http://localhost/phpmyadmin
  5. Create a database cicrud
  6. Import sql file cicrud.sql
  7. Run your script http://localhost/cicrud

CRUD Operation in CodeIgniter (Download full script)
Size: 4.46 MB
Version: V 1

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...

Leave a Reply

Your email address will not be published. Required fields are marked *