Business Directory and Listing Development
In today’s highly competitive digital world, businesses must find innovative ways to gain visibility, attract customers, and boost local reach. One effective and time-tested strategy is developi
Read MoreSign Up Now and Get FREE CTO-level Consultation.
If you're starting web development using PHP, one of the first concepts you'll learn is CRUD Operations. Every dynamic application—from student management systems to eCommerce websites—depends on CRUD functionality.
Using CodeIgniter, developers can build CRUD applications much faster while keeping the code organized and secure. CodeIgniter follows the MVC (Model-View-Controller) architecture, making development simple even for beginners.
In this guide, you'll learn PHP CodeIgniter Basic CRUD Operation with MySQL Database, understand how each component works, and build a simple employee management application step by step.
CRUD stands for:
C – Create
R – Read
U – Update
D – Delete
These four operations allow users to interact with database records.
For example:
Add a new employee
View employee details
Edit employee information
Delete employee records
Almost every web application uses CRUD functionality.
CodeIgniter is one of the most popular PHP frameworks because it is lightweight, fast, and easy to learn.
Simple MVC architecture
Excellent database support
Built-in security features
Fast performance
Easy routing
Reusable code
Less configuration
Beginner-friendly
Whether you're creating a blog, CRM, ERP, school management software, or inventory system, CRUD is the foundation of every project.
Before starting, install the following:
PHP 8.x
CodeIgniter
MySQL
Apache Server
XAMPP or WAMP
Visual Studio Code
phpMyAdmin
CodeIgniter follows MVC.
The Model communicates with the database.
Example:
Insert records
Update records
Delete records
Fetch records
The View displays data to users.
Examples:
HTML pages
Forms
Tables
Bootstrap UI
The Controller connects Models and Views.
It receives requests, processes data, and returns responses.
Create a database.
CREATE DATABASE employee_db;
Create a table.
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
phone VARCHAR(20)
);
A simple CRUD project usually contains:
application/
controllers/
Employee.php
models/
Employee_model.php
views/
employee_list.php
employee_add.php
employee_edit.php
Each file has a specific responsibility, making the application easy to maintain.
application/config/database.php
Example:
$db['default'] = array(
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'employee_db',
'dbdriver' => 'mysqli'
);
Now CodeIgniter can communicate with MySQL.
Models handle database queries.
Example:
class Employee_model extends CI_Model {
public function getEmployees()
{
return $this->db->get('employees')->result();
}
}
The Model keeps SQL queries separate from business logic.
Controllers process user requests.
Example:
class Employee extends CI_Controller {
public function index()
{
$data['employees']=$this->Employee_model->getEmployees();
$this->load->view('employee_list',$data);
}
}
The controller loads data and sends it to the view.
Views display information.
Example:
<table>
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</table>
Views should contain presentation code only.
Example:
Employee Name
Employee Email
Employee Phone
After clicking Submit, data is saved into MySQL.
Model:
public function insertEmployee($data)
{
$this->db->insert('employees',$data);
}
Read retrieves data from the database.
Example:
public function getEmployees()
{
return $this->db->get('employees')->result();
}
Output:
| ID | Name | | Phone |
| 1 | John | john@gmail.com | 9876543210 |
| 2 | David | david@gmail.com | 9999999999 |
Update edits existing records.
Example:
$this->db->where('id',$id);
$this->db->update('employees',$data);
Users can modify employee details without creating duplicate records.
Delete removes records permanently.
Example:
$this->db->where('id',$id);
$this->db->delete('employees');
Usually, applications display a confirmation message before deletion.
The CRUD process follows this simple flow:
User opens the Employee page.
Employee list loads from MySQL.
User clicks Add Employee.
Form is submitted.
Data is validated.
Record is inserted.
Employee list refreshes.
User edits an employee.
Updated data is saved.
User deletes an employee if needed.
Never trust user input.
CodeIgniter provides validation rules.
Example:
$this->form_validation->set_rules('name','Name','required');
$this->form_validation->set_rules('email','Email','required|valid_email');
Validation prevents invalid data from entering your database.
When building CRUD applications:
Validate every form.
Escape user input.
Enable CSRF protection.
Use prepared database queries.
Filter XSS attacks.
Never expose database credentials.
Limit user permissions.
Keep CodeIgniter updated.
These practices improve both security and application reliability.
Using CodeIgniter for CRUD offers several advantages:
Clean project structure
Faster development
Easy maintenance
Better performance
Built-in database library
Secure query builder
Reusable components
Easy debugging
Scalable architecture
CRUD operations are used in almost every business application, including:
Student Management Systems
Employee Management Software
Hospital Management Systems
CRM Software
Inventory Management
Hotel Booking Systems
eCommerce Websites
Food Ordering Platforms
School ERP
HR Management Systems
Beginners often encounter these issues:
Check database credentials and server status.
Verify the table name in your queries.
Ensure variables are passed correctly from the controller to the view.
Confirm routes and controller names.
Make sure validation rules match your form fields.
Follow MVC principles.
Keep controllers lightweight.
Place all database queries in models.
Use meaningful variable names.
Validate all user inputs.
Reuse common functions.
Separate business logic from presentation.
Test every CRUD operation before deployment.
Maintain proper folder organization.
Document your code for future maintenance.
Learning PHP CodeIgniter Basic CRUD Operation with MySQL Database is one of the most important steps for every PHP developer. CRUD operations form the backbone of nearly every dynamic web application, from small business websites to enterprise-level software.
CodeIgniter simplifies database management with its MVC architecture, Query Builder, and built-in libraries, allowing developers to create secure, maintainable, and scalable applications efficiently. Once you understand how to create, read, update, and delete records, you'll be ready to build more advanced systems such as user authentication, inventory management, CRM platforms, school management systems, and eCommerce applications.
By following best practices like input validation, secure database handling, and clean code organization, you can develop reliable applications that are easier to maintain and scale over time.
In short, mastering CRUD operations in CodeIgniter provides a strong foundation for modern PHP web development and prepares you for building real-world applications with confidence.
It is the process of creating, reading, updating, and deleting records stored in a MySQL database using the CodeIgniter PHP framework. These four operations are the foundation of most dynamic web applications.
CRUD enables developers to manage database records efficiently. Almost every web application—including blogs, eCommerce stores, HR systems, and CRMs—depends on CRUD functionality for everyday operations.
Yes. CodeIgniter is lightweight, easy to learn, and follows the MVC architecture. Its clear structure, excellent documentation, and built-in tools make it an ideal framework for beginners learning PHP development.
MySQL is the most commonly used database with CodeIgniter due to its speed, reliability, and compatibility. However, CodeIgniter also supports PostgreSQL, SQLite, SQL Server, and other database systems.
The four CRUD operations are:
Create: Add new records.
Read: Retrieve existing records.
Update: Modify existing records.
Delete: Remove records from the database.
MVC separates the application into Models, Views, and Controllers. This improves code organization, simplifies maintenance, encourages code reuse, and makes the application easier to scale and test.
Yes. CodeIgniter provides a Query Builder that lets you perform CRUD operations using PHP methods, reducing the need to write raw SQL while improving security and readability.
You can secure your application by validating user input, enabling CSRF protection, escaping output to prevent XSS attacks, using prepared queries through CodeIgniter’s Query Builder, and keeping your framework updated.
CRUD operations are used in employee management systems, school portals, inventory software, healthcare applications, customer relationship management (CRM), hotel booking platforms, eCommerce websites, and many other database-driven applications.
Absolutely. Once the basic CRUD functionality is in place, you can extend your application with features such as user authentication, role-based access control, search, pagination, file uploads, REST APIs, reporting dashboards, and AJAX integration for a richer user experience.
Request a FREE Business Plan.
+91 ▼
In today’s highly competitive digital world, businesses must find innovative ways to gain visibility, attract customers, and boost local reach. One effective and time-tested strategy is developi
Read More
Welcome to the Era of Intelligent Mobile Apps Mobile apps are much more than just tools for browsing, booking, and communicating in today's hyper connected digital world. They are becoming perc
Read More
In today’s competitive digital landscape, having a strong online presence is vital for businesses of all sizes. ECommerce websites are the backbone of modern retail, providing companies with a p
Read More