/home/hdwebsolution/www/sareenn/application/models/General_model.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class General_model extends CI_Model
{
public function __construct()
{
$this->load->database();
}
public function get_all($table)
{
if ($query = $this->db->get($table)) {
return $query->result_array();
} else {
return FALSE;
}
}
public function get_row($table)
{
if ($query = $this->db->get($table)) {
return $query->row();
} else {
return FALSE;
}
}
public function get_all_where($table, $key, $key_value, $key2 = NULL , $key2_value = NULL)
{
$this->db->select('*');
$this->db->where($key, $key_value);
if(!$key2 == NULL && !$key2_value == NULL)
{
$this->db->where($key2, $key2_value);
}
$query = $this->db->get($table);
if ($query) {
return $query->result_array();
} else {
return FALSE;
}
}
public function get_by_where($table, $key, $key_value, $key2 = NULL , $key2_value = NULL)
{
$this->db->select('*');
$this->db->where($key, $key_value);
if(!$key2 == NULL && !$key2_value == NULL)
{
$this->db->where($key2, $key2_value);
}
$query = $this->db->get($table);
if ($query) {
return $query->row();
} else {
return FALSE;
}
}
public function insert_request($table, $insert_data)
{
if ($this->db->insert($table, $insert_data)) {
return $this->db->insert_id();
} else {
return FALSE;
}
}
public function update_table_value($table, $key, $key_value, $column_name, $column_value)
{
$this->db->set($column_name, $column_value);
$this->db->where($key, $key_value);
if ($this->db->update($table)) {
return TRUE;
} else {
return FALSE;
}
}
public function update_request($table, $key, $key_value, $update_data)
{
if ($this->db->update($table, $update_data, array($key => $key_value))) {
return TRUE;
} else {
return FALSE;
}
}
public function update_request_where($table, $column_name, $column_value, $key, $key_value, $update_data)
{
$this->db->where($column_name, $column_value);
if ($this->db->update($table, $update_data, array($key => $key_value))) {
return TRUE;
} else {
return FALSE;
}
}
public function delete_request($table, $key, $key_value)
{
if ($this->db->delete($table, array($key => $key_value))) {
return TRUE;
} else {
return FALSE;
}
}
public function delete_request_where($table, $column_name, $column_value, $key, $key_value)
{
$this->db->trans_start();
$this->db->where($column_name, $column_value);
$this->db->where($key, $key_value);
$this->db->delete($table);
$this->db->trans_complete();
if($this->db->trans_status() === FALSE){
return FALSE;
}else{
return TRUE;
}
}
public function check_record_exists($table, $key, $key_value, $key2 = NULL , $key2_value = NULL)
{
$this->db->where($key, $key_value);
if(!$key2 == NULL && !$key2_value == NULL)
{
$this->db->where($key2, $key2_value);
}
$query = $this->db->get($table);
if ($query->num_rows() > 0) {
return TRUE;
} else {
return FALSE;
}
}
}