Advertisement
dewa_01

Untitled

Dec 15th, 2019
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Model_products extends CI_Model {
  4.  
  5.     public function all(){
  6.         //query semua record di table products
  7.         $hasil = $this->db->get('products');
  8.         if($hasil->num_rows() > 0){
  9.             return $hasil->result();
  10.         } else {
  11.             return array();
  12.         }
  13.     }
  14.    
  15.     public function find($id){
  16.         //Query mencari record berdasarkan ID-nya
  17.         $hasil = $this->db->where('id', $id)
  18.                           ->limit(1)
  19.                           ->get('products');
  20.         if($hasil->num_rows() > 0){
  21.             return $hasil->row();
  22.         } else {
  23.             return array();
  24.         }
  25.     }
  26.    
  27.     public function create($data_products){
  28.         //Query INSERT INTO
  29.         $this->db->insert('products', $data_products);
  30.     }
  31.  
  32.     public function update($id, $data_products){
  33.         //Query UPDATE FROM ... WHERE id=...
  34.         $this->db->where('id', $id)
  35.                  ->update('products', $data_products);
  36.     }
  37.    
  38.     public function delete($id){
  39.         //Query DELETE ... WHERE id=...
  40.         $this->db->where('id', $id)
  41.                  ->delete('products');
  42.     }
  43.    
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement