Create-Read-Update-Delete (CRUD) in codeigniter

CodeIgniter (CI) is one of popular PHP framework. If you are already building PHP Application, CodeIgniter will help you to do it better and more easily.  For example, they can create web page (that to do basic Create, Read, Update, and Delete ) CRUD automatically.

In this post, we are going to create simple CRUD (Create-Read-Update-Delete) application using CodeIgniter framework. Its very hectic to have same structured  model every time for every controller, so it’s a good practice to have a generic method’s for all controller which is further very easy to remember and use.
so i came with some generic model which can be used by every middle or high level project and customised as per requirement.

you can refer to Code Igniter Active Record Class page.


The basic use can be as follows

From a controller we can call model’s function as below given.

Beyond the simplicity of codeigniter, a major benefit to using the Active Record features is that it allows you to create database independent applications, since the query syntax is generated by each database adaptor. It also allows for safer queries, since the values are escaped automatically by the system.

Following are some quick review of Active Record Query function available in codeigniter.

Use of Query:

Use Of Query Bindings

Benefit of using binds is that the values are automatically escaped, producing safer queries

Use the built – in get() method

Select the fields with get() method

Select the fields with limit in get() method

Fields selection with where, or_where, where_in, or_where_in, where_not_in method

Use of get_where() method in codeigniter

Use of get() method with With Like, or_like, not_like, or_not_like

get() method with group_by clause

get() method with having clause

get() method with order by clause

Mathematics Function In Codeigniter

Available joins types in codeigniter i.e left, right, outer, inner, left outer, and right outer

Query Result by result() method

Count of Query Result count_all() method


That’s it folks!


Print Friendly, PDF & Email

Leave a Reply

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