Untitled
unknown
php
3 years ago
1.9 kB
6
Indexable
<?php defined('BASEPATH') or exit('No direct script access allowed'); class Data extends CI_Model { public function __construct() { parent::__construct(); } public function get($table, $condition, $select = "*") { $query = $this->db->query("SELECT $select FROM $table $condition"); return $query->num_rows() ? $query->row() : null; } public function gets($table, $condition = "", $select = "*") { $query = $this->db->query("SELECT $select FROM $table $condition"); return $query->num_rows() ? $query->result() : null; } public function set($table, $data) { $this->db->insert($table, $data); $get = $this->get("`$table`", "WHERE id=" . $this->db->insert_id()); return $get; } public function update($table, $data, $key, $column = "id") { $query = $this->get($table, "WHERE $column = '$key'"); if (!is_null($query)) { $this->db->where($column, $key); $this->db->update($table, $data); return $query; } return; } public function delete($table, $id) { $row = $this->get($table, "WHERE id=" . $id); $this->db->where('id', $id); $this->db->delete($table); return $row; } public function getUser($field, $name) { return $this->db->select('*')->where($field, $name)->get('users')->row(); } public function getCustomers($user_id) { return $this->db->where('user_id =', $user_id)->order_by('updated', 'DESC')->get('customer')->result(); } public function getMessages($phone) { return $this->db->where('sender =', $phone)->or_where('receiver =', $phone)->order_by('created', 'ASC')->get('message')->result(); } }
Editor is loading...