CRUD operation in CodeIgniter


- Advertisement -

In this tutorial we will learn about 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/config/database.php

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

  • Database library used for database related queries
  • Session library used for display success/error message using flash data.
  • 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 ——————————————————-

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

- Advertisement -

Leave A Reply

Your email address will not be published.

1 Comment
  1. satish b says

    nice demo anuj.

Leave A Reply

Your email address will not be published.