Skip to main content

How to create functions in model in Codeigniter?

 Create functions in the model in Codeigniter


 Delete, Fetch, Insert and Update functions in Codeigniter


<?php 
class Customer_model extends CI_Model {
 
    /**
    * Responsable for auto load the database
    * @return void
    */
    public function __construct()
    {
        $this->load->database();
        $this->load->helper('url');
    }

    /**
    * Get product by his is
    * @param int $product_id 
    * @return array
    */

   

   public function get_login_data()
    {
$this->db->select('*');
$this->db->from('login_form');
$query = $this->db->get();
return $query->result_array(); 
    }

public function login_detail($email,$password)
    {
$this->db->select('*');
$this->db->from('login_form');
$this->db->where('email',$email);
$this->db->where('password',$password);
$query = $this->db->get();
return $query->result_array(); 
    }
public function get_single_user_detail($user_id)
    {
$this->db->select('*');
$this->db->from('login_form');
$this->db->where('ID',$user_id);
$query = $this->db->get();
return $query->result_array(); 
    }
function register_user($name,$phone,$email,$password){

$data = array(
'name' => $name,
'phone' => $phone,
'email ' => $email,
'password ' => $password
);
$this->db->insert('login_form', $data);
}
function delete_user($user_id){
$this -> db -> where('ID', $user_id);
$this -> db -> delete('login_form');
}


function update_user($user_id,$name,$phone,$email,$password){
$data = array(
'name' => $name,
'phone' => $phone,
'email ' => $email,
'password ' => $password
);
$this->db->update('login_form', $data);
$this -> db -> where('ID', $user_id);
}
}


Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...