106 lines
2.0 KiB
PHP
106 lines
2.0 KiB
PHP
|
<?php
|
||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||
|
|
||
|
class Common_model extends CI_Model {
|
||
|
|
||
|
public function __construct(){
|
||
|
|
||
|
parent::__construct();
|
||
|
|
||
|
}
|
||
|
public function getAllData($tbl,$where)
|
||
|
{
|
||
|
$this->db->select('*');
|
||
|
$this->db->from($tbl);
|
||
|
$this->db->where($where);
|
||
|
$query = $this->db->get();
|
||
|
return $query->result_array();
|
||
|
}
|
||
|
|
||
|
public function update($table, $data, $where)
|
||
|
{
|
||
|
|
||
|
$this->db->where($where);
|
||
|
$this->db->update($table, $data);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
public function update_data($table, $data, $where)
|
||
|
{
|
||
|
|
||
|
$this->db->where($where);
|
||
|
$this->db->update($table, $data);
|
||
|
$afftectedRows = $this->db->affected_rows();
|
||
|
echo $afftectedRows;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
public function delete($table, $where)
|
||
|
{
|
||
|
|
||
|
$this->db->where($where);
|
||
|
$this->db->delete($table);
|
||
|
$query=$this->db->get($table);
|
||
|
return $query->result();
|
||
|
|
||
|
}
|
||
|
|
||
|
public function deleteDynamicRow($table,$where){
|
||
|
|
||
|
$this->db->where($where);
|
||
|
$delete = $this->db->delete($table);
|
||
|
return $delete?true:false;
|
||
|
}
|
||
|
|
||
|
|
||
|
public function insert_or_update($table,$where, $data){
|
||
|
$this->db->where($where);
|
||
|
$q = $this->db->get($table);
|
||
|
|
||
|
if( $q->num_rows() > 0 )
|
||
|
{
|
||
|
$this->db->where($where);
|
||
|
$this->db->update($table,$data);
|
||
|
} else {
|
||
|
$this->db->set($where);
|
||
|
$this->db->insert($table, $data);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
public function set_data($table, $where, $data)
|
||
|
{
|
||
|
|
||
|
$this->db->update($table, $data, $where);
|
||
|
return $this->db->affected_rows();
|
||
|
|
||
|
}
|
||
|
|
||
|
public function set_token($email, $randon)
|
||
|
{
|
||
|
|
||
|
$where = array('admin_email' => $email);
|
||
|
$this->db->update('tbl_admin', $randon, $where);
|
||
|
return $this->db->affected_rows();
|
||
|
|
||
|
}
|
||
|
|
||
|
public function insert_or_delete($table,$where, $data){
|
||
|
|
||
|
$this->db->where($where);
|
||
|
$q = $this->db->get($table);
|
||
|
|
||
|
if( $q->num_rows() > 0 )
|
||
|
{
|
||
|
$this->db->where($where);
|
||
|
$this->db->delete($table,$data);
|
||
|
} else {
|
||
|
$this->db->set($where);
|
||
|
$this->db->insert($table, $data);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|