CodeIgniter Database CRUD Tutorial for Beginners with Examples
CRUD is one of the primary functions of a Database Management System.It stands for the four basic operations Create, Read, Update and Delete performed on databases. In SQL, it represents INSERT (Create), SELECT (Read), UPDATE (Update) and DELETE (Delete) commands. Learning the Database CRUD process is essential in application development especially when you want to work with databases. In this codeigniter tutorial, we'll see about building database CRUD operations using CodeIgniter and MySQL Database in detail.
Building Database CRUD Operations in CodeIgniter
To understand CRUD in a simple way, let us consider an example say you develop a web application which handles employee details of a business venture. At the minimum level the application should allow to add (Create), list (Read), update and delete the employee records. So to implement a CRUD process in applications, you should develop some user interface for the user to perform the above said tasks.
Codeigniter follows model-view-controller architecture, and building CRUD process in codeigniter is little tricky with those model, view and controller files. But never mind, this article will take you step by step to create basic crud process using codeigniter and mysql.
CodeIgniter CRUD Example
As an example let us assume that we have to build CRUD for employee’s details. First we'll see how many codeigniter controllers, models and views we require.
Obviously you need one controller file with all the four CRUD functions, one model file for database access and different view files for user interface. The create and update process will share a single view file and another to list the employee details in grid and delete don't require separate view file at all.
The controller for Employee CRUD will look something like this,
<?php class employeeCRUD extends CI_Controller { public function __construct() { ... } function index() { ... } function addEmployee() { // database insert code } function fetchEmployee() { // database fetch code } function updateEmployee() { // database update code } function deleteEmployee() { // database delete code } } ?>
No comments:
Post a Comment