codeigniter crud – Codeigniter 3 CRUD Operation with Bootstrap and MySQL Example functionality with Bootstrap and MySQL Example. A CodeIgniter CRUD application is one that uses forms to get data into and out of a mysql database. CRUD is an acronym for Create, Read, Update, and Delete. CRUD operations are basic data manipulation for database.
Codeigniter 3 – Basic CRUD Operation with MySQL Database with example
In this codeigniter crud tutorial i will learn about CRUD operation in PHP CodeIgniter. CRUD Stands for create, read, update and delete record in the MySQL database.
Step 1: Download Codeigniter App
First of all i need to free download the Codeigniter 3 source code just go the PHP Based Codeigniter website as well as free 100% Download. And then downloading extract the folder as well as add it in your local system like path as a xampp/htdocs/.
Step 2: Basic Configurations for codeigniter crud
If you are using virtual host then add Or if you run the project with folder name
$config['base_url'] = 'https://www.pakainfo.com'; //OR $config['base_url'] = 'http://localhost/codeigniter-crud';
Step 3: Setup Database Credential
application/config/database.php
$db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root', 'password' => 'admin', 'database' => 'product_data', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE );
Step 3: Create Database Table
And then execute following simple SQL Query with selecting the database in phpmyadmin and make “shops” table for codeigniter crud.
CREATE TABLE `paakinfo_v1` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255), `information` text, PRIMARY KEY (`id`) )
Step 4: Create Routes
application\config\routes.php
Step 5: Create Controller
application\controllers\Shop.php
load->helper('url'); $this->load->library('session'); $this->load->database(); } public function index() { $shops = $this->db->get('shops')->result(); $this->load->view('shop/index', ['shops' => $shops]); } public function create() { $this->load->view('shop/create'); } public function edit($id) { $shop = $this->db->where(['id' => $id])->get('shops')->row(); $this->load->view('shop/edit', ['shop' => $shop]); } public function store() { $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Name', 'required'); $this->form_validation->set_rules('information', 'Information','required'); if ($this->form_validation->run()) { $shop = array ( 'name' => $this->input->post('name'), 'information' => $this->input->post('information'), ); $this->db->insert('shops', $shop); } else { $errors = $this->form_validation->error_array(); $this->session->set_flashdata('errors', $errors); redirect(base_url('shop/create')); } redirect('/shop'); } public function update($id) { $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Name', 'required'); $this->form_validation->set_rules('information', 'Information', 'required'); if ($this->form_validation->run()) { $shop = array ( 'name' => $this->input->post('name'), 'information' => $this->input->post('information'), ); $this->db->where(['id' => $id])->update('shops', $shop); } else { $errors = $this->form_validation->error_array(); $this->session->set_flashdata('errors', $errors); redirect(base_url('shop/edit/'. $id)); } redirect('/shop'); } public function show($id) { $shop = $this->db->where(['id' => $id])->get('shops')->row(); $this->load->view('shop/show',['shop' => $shop]); } public function delete($id) { $this->db->where(['id' => $id])->delete('shops'); redirect('/shop'); } }Step 6: Create Views
application\views\shop\index.php
Basic Crud operation in Codeigniter 3 Codeigniter 3 CRUD Example from scratch with pakainfo
Name Information Action name; ?> information; ?> Creating New shop
For making fresh shop i need to show the form using the create.php file, make and put the below source code inside the file.
application\views\shop\create.phpBasic Crud operation in Codeigniter 3 - codeigniter crud Create Shop
Edit the shop
Now edit the shop using the edit.php file.
application\views\shop\edit.phpBasic Crud operation in Codeigniter 3 Update Shop
Showing the shop
Showing the shop we need to create a show.php file.
application\views\shop\show.phpBasic Crud operation in Codeigniter 3 Conclusion - codeigniter crud
In this codeigniter basic crud article with Codeigniter Config – I have successfully created step by step first basic crud (create, update, read, delete) full source code using mysql database.