example_model.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. class Example_model extends MY_Model
  3. {
  4. private $table_name = 'example';
  5. private $orderby = 'ord';
  6. public function insert($parm)
  7. {
  8. $this->db->insert($this->table_name, $parm);
  9. return $this->db->insert_id();
  10. }
  11. public function delete($id) {
  12. $this->db->where('id', $id);
  13. $this->db->delete($this->table_name);
  14. return $this->db->affected_rows();
  15. }
  16. public function update($id, $parm) {
  17. $this->db->where('id', $id);
  18. $this->db->update($this->table_name, $parm);
  19. return $this->db->affected_rows();
  20. }
  21. public function get($id)
  22. {
  23. $this->db->select('*');
  24. $this->db->from($this->table_name);
  25. $this->db->where('id', $id);
  26. $query = $this->db->get();
  27. return $query->num_rows() > 0 ? $query->row_array() : false;
  28. }
  29. public function all($type)
  30. {
  31. $this->db->where('type', $type);
  32. $this->db->order_by($this->orderby, 'asc');
  33. $query = $this->db->get($this->table_name);
  34. return $query->num_rows() > 0 ? $query->result_array() : false;
  35. }
  36. public function max_ord($type)
  37. {
  38. $this->db->where('type', $type);
  39. $this->db->select('max(ord) as max_ord');
  40. $query = $this->db->get($this->table_name);
  41. $ret = $query->row_array();
  42. return $ret['max_ord'];
  43. }
  44. }