Advertisement
Bedhoel

model/General_Model.php

Jun 25th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.17 KB | None | 0 0
  1. <?php
  2. class General_Model {
  3.     function Insert($table='',$data=array()){
  4.           global $db;
  5.           $qry = "INSERT INTO ".$table."(";
  6.             foreach ($data as $key => $value) {
  7.                 $kez[]=$key;
  8.                 $val[]="'".$value."'";
  9.             }
  10.         $qry =$qry.implode(' , ', $kez).") VALUES( ".implode(' , ',$val).")";
  11.         $result=$db->execute($qry);
  12.         if (!$result){
  13.             return $db->ErrorMsg();
  14.         }
  15.         else{
  16.             return "OK";
  17.         }
  18.     }
  19.     function Update($table='',$data=array(),$whr=array()){
  20.         global $db;
  21.  
  22.         $qry = "UPDATE ".$table." SET ";
  23.         foreach ($data as $key => $value) {
  24.             $qrr[]= $key." = '".$value."'";
  25.         }
  26.         if(!empty($whr)){
  27.             foreach ($whr as $key => $value) {
  28.                 $whrr[]= $key." = '".$value."'";
  29.             }
  30.             $data =$qry.implode(' , ', $qrr)." WHERE ".implode(' and ',$whrr);
  31.         }      
  32.         else {
  33.             $data =$qry.implode(' , ', $qrr);
  34.         }
  35.         $result=$db->execute($data);
  36.         if (!$result){
  37.             return $db->ErrorMsg();
  38.         }
  39.         else{
  40.             return "OK";
  41.         }
  42.     }
  43.     function Delete($table="",$whr=array()){
  44.         global $db;
  45.        
  46.         if(!empty($whr)){
  47.             $qry="DELETE FROM ".$table." WHERE ";
  48.             foreach ($whr as $key => $value) {
  49.                 $arr[]=$key." = '".$value."'";
  50.             }
  51.             $data=$qry.implode(' and ', $arr);
  52.         }
  53.         else {
  54.             $qry="DELETE FROM ".$table;
  55.         }
  56.        
  57.        
  58.         $result=$db->execute($data);
  59.         if (!$result){
  60.             return $db->ErrorMsg();
  61.         }
  62.         else{
  63.             return "OK";
  64.         }
  65.     }
  66.     function GetOne($coloumn="",$table="",$whr=array()){
  67.         global $db;
  68.         if(!empty($whr)){
  69.             $qry="Select ".$coloumn." FROM ".$table." WHERE ";
  70.             foreach ($whr as $key => $value) {
  71.                 $arr[]=$key." = '".$value."'";
  72.             }
  73.             $data=$qry.implode(' and ', $arr); 
  74.         }
  75.         else {
  76.             $data="Select ".$coloumn." FROM ".$table;      
  77.         }
  78.         $result=$db->getOne($data);
  79.         if (!$result){
  80.             return $db->ErrorMsg();
  81.         }
  82.         else{
  83.             return $result;
  84.         }
  85.     }
  86.     function GetOneRow($table='',$arr=array()){
  87.         global $db;
  88.  
  89.         if(!empty($arr)){
  90.             $qry = "SELECT * FROM ".$table." WHERE ";
  91.             foreach ($arr as $key => $value) {
  92.                 $qrr[]= $key." = '".$value."'";
  93.             }
  94.             $data =$qry.implode(' and ', $qrr);
  95.         }
  96.         else {
  97.             $data = "SELECT * FROM ".$table;
  98.         }
  99.        
  100.         $result=$db->getRow($data);
  101.         if (!$result){
  102.             return $db->ErrorMsg();
  103.         }
  104.         else {
  105.             return $result;
  106.         }
  107.     }
  108.     function GetWhere($table='',$arr=array()){
  109.         global $db;
  110.  
  111.         if(!empty($arr)){
  112.             $qry = "SELECT * FROM ".$table." WHERE ";
  113.             foreach ($arr as $key => $value) {
  114.                 $qrr[]= $key." = '".$value."'";
  115.             }
  116.             $data =$qry.implode(' and ', $qrr);
  117.         }
  118.         else {
  119.             $data = "SELECT * FROM ".$table;
  120.         }
  121.  
  122.         $result=$db->execute($data);
  123.         if (!$result){
  124.             return $db->ErrorMsg();
  125.         }
  126.         else {
  127.             return $result;
  128.         }
  129.        
  130.     }
  131.     function GetMaxMin($col,$table,$tipe,$whr=array()){
  132.         global $db;
  133.         if(!empty($whr)){
  134.             $qry="Select ".$col." FROM ".$table." WHERE ";
  135.             foreach ($whr as $key => $value) {
  136.                 $arr[]=$key." = '".$value."'";
  137.             }
  138.             $data=$qry.implode(' and ', $arr);
  139.             $data.= " order by ".$col." ".$tipe;    
  140.         }
  141.         else {
  142.             $data="Select ".$col." FROM ".$table;
  143.             $data.= " order by ".$col." ".$tipe;           
  144.         }
  145.         $result=$db->getOne($data);
  146.         if (!$result){
  147.             return $db->ErrorMsg();
  148.         }
  149.         else{
  150.             return $result;
  151.         }
  152.     }
  153. }
  154.  
  155. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement