class xyz_model extends CI_Model {
const TABLE_NAME = 'xyz';
public function __construct() {
$this->load->database();
}
public function saveData($data) {
$return_id = 0;
if (!empty($data)) {
$insert_status = $this->db->insert(self::TABLE_NAME, $data);
if ($insert_status) {
$return_id = $this->db->insert_id();
}
}
return $return_id;
}
public function updateData($update_params, $condition_params) {
$return_status = 0;
if (!empty($update_params) && !empty($condition_params)) {
$this->db->where($condition_params);
$this->db->update(self::TABLE_NAME, $update_params);
$return_status = $this->db->affected_rows();
}
return $return_status;
}
public function getData($id, $fields = '') {
$return_result = array();
if ($id > 0) {
if (!empty($fields)) {
$this->db->select($fields);
}
$result = $this->db->get_where(self::TABLE_NAME, array(
'id' => $id
), $limit = 1, $offset = 0);
if ($result && $result->num_rows() > 0) {
$return_result = $result->result_array();
}
}
return $return_result;
}
public function delete($id) {
return $this->db->delete(self::TABLE_NAME, array(
'id' => $id
));
}
}
No comments:
Post a Comment