Delete Data in CodeIgniter Example

In this post we learn delete data in CodeIgniter example. we will explain step by step how to delete data from database in CodeIgniter. also i will show delete data from from database using CodeIgniter. you can simply delete data in CodeIgniter using delete() function.

Delete Data From Database CodeIgniter

Create Demo.php controller.

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Demo extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('demo_model');
    }
    
    function delete_demo(){
        $this->demo_model->delete('demo', array("id" => 1));
    }
    
    
}


Create Demo_model.php model.

<?php

class Demo_model extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }
    
    /**
     * @param $table_name
     * @param $where_array
     * @return mixed
     */
    function delete($table_name,$where_array){		
        $result = $this->db->delete($table_name,$where_array);
        return $result;
    }
}

I hope you understand of delete data from database in codeigniter and it can help you…