Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.51 KB | None | 0 0
  1. <?php
  2.     /*
  3.      * Klasė C-main 1.0.1
  4.      * Sukurta : 2011.06.08
  5.      * Autorius : Aurimas Gerčas
  6.      */
  7.     class cmain {
  8.        
  9.  
  10.        
  11.         /* naudojama insert */
  12.         private $insert_first = array();
  13.         private $insert_last = array();  
  14.  
  15.        
  16.         private $back = array();
  17.        
  18.        
  19.         public function __construct($host, $user, $pass, $db) {
  20.  
  21.             $this->host = $host;
  22.             $this->user = $user;
  23.             $this->pass = $pass;
  24.             $this->db   = $db;
  25.  
  26.             $this->link = mysql_pconnect("$this->host","$this->user","$this->pass");
  27.             mysql_select_db($this->db,$this->link) or die (mysql_error());
  28.                        
  29.         }
  30.        
  31.  
  32.        
  33.         public function insert($tbl,$data) {
  34.            
  35.             $this->tbl = $tbl;
  36.            
  37.            
  38.             foreach ($data as $name=>$value)
  39.             {
  40.            
  41.                 $this->insert_first[] = $name;
  42.                 $this->insert_last[]= $value;
  43.  
  44.                 $this->back[$name] = $value;
  45.  
  46.             }
  47.  
  48.             $this->insert_first = '(`'.implode('`,`',$this->insert_first).'`)';
  49.             $this->insert_last = "(".implode(",",$this->insert_last).")";
  50.  
  51.            
  52.             mysql_query("INSERT INTO  `$this->tbl` $this->insert_first VALUES $this->insert_last ");
  53.             //echo "INSERT INTO  $this->tbl $this->insert_first VALUES $this->insert_last";
  54.             return ($this->back);
  55.        
  56.            
  57.         }
  58.        
  59.  
  60.         public function update ($tbl,$where,$data){
  61.  
  62.             $this->where = array();
  63.            
  64.             foreach ($where as $key=>$value){
  65.            
  66.                 $this->where[] = "$key = $value";
  67.                            
  68.             }
  69.            
  70.             $this->where = implode (' AND ', $this->where);
  71.            
  72.             /* foreach sudarantis update */
  73.             foreach ($data as $key=>$value){
  74.                            
  75.                 $this->update[] = "`$key` = $value";
  76.                            
  77.             }
  78.            
  79.             $this->update  = implode (',',$this->update);
  80.            
  81.             mysql_query("UPDATE `$tbl` SET $this->update WHERE $this->where");
  82.             //echo "UPDATE `$tbl` SET $this->update WHERE $this->where";
  83.         }
  84.  
  85.                
  86.         public function select ($tbl,$where){
  87.            
  88.              $this->where = array();
  89.              
  90.              
  91.              foreach ($where as $key=>$value){
  92.            
  93.                 $this->where[]= "`$key` = $value";
  94.                            
  95.             }
  96.            
  97.             $this->where = implode (' AND ', $this->where);          
  98.  
  99.             if (empty($this->where)){            
  100.                 $result = mysql_query("SELECT * FROM `$tbl`",$this->link);    
  101.             }
  102.             if (!empty ($this->where)){            
  103.                 $result = mysql_query("SELECT * FROM `$tbl` WHERE $this->where");
  104.             }
  105.                            
  106.            
  107.             while ($row = mysql_fetch_array( $result )) {
  108.                 $this->back[] = $row ;
  109.             }
  110.            
  111.             return ($this->back);
  112.         }
  113.        
  114.        
  115.        
  116.         public function delete ($tbl,$where){
  117.            
  118.             $this->where = array();
  119.            
  120.             foreach ($where as $key=>$value){
  121.            
  122.                 $this->where[]= "`$key` = $value";
  123.                            
  124.             }
  125.            
  126.             $this->where = implode (' AND ', $this->where);
  127.            
  128.             $result = mysql_query("DELETE FROM $tbl WHERE $this->where");
  129.  
  130.  
  131.         }
  132.        
  133.        
  134.         public function num_rows ($tbl, $where){
  135.            
  136.             $this->where = array();
  137.            
  138.             foreach ($where as $key=>$value){
  139.            
  140.                 $this->where[]= "`$key` = $value";
  141.                
  142.                            
  143.             }
  144.            
  145.             $this->where = implode (' AND ', $this->where);
  146.            
  147.             $result = mysql_query("SELECT * FROM $tbl WHERE $this->where");
  148.  
  149.            
  150.             $rows = mysql_num_rows($result);
  151.  
  152.             return ($rows);
  153.         }
  154.        
  155.        
  156.         public function search($tbl, $fields){
  157.             $this->where = array();
  158.            
  159.             foreach ($fields as $key=>$value){
  160.                 if (empty($value)) continue;
  161.                 $this->where[]= "`$key` = '$value'";
  162.              }
  163.            
  164.             $this->where = implode (' AND ', $this->where);
  165.            
  166.             $result = mysql_query("SELECT * FROM $tbl WHERE $this->where");
  167.            
  168.             //echo "SELECT * FROM $tbl WHERE $this->where";
  169.            
  170.             while ($row = mysql_fetch_array( $result )) {
  171.                 $this->back[] = $row ;
  172.             }
  173.            
  174.             return ($this->back);
  175.         }
  176.        
  177.        
  178.         public function __destruct() {
  179.            
  180.             mysql_close($this->link);
  181.            
  182.         }
  183.        
  184.  
  185.        
  186.     }
  187.  
  188.  
  189.    
  190.     $obj  = &new cmain(host, user, pass, db);
  191.     $obj1 = &new cmain(host, user, pass, db);
  192.     $obj2 = &new cmain(host, user, pass, db);
  193.     $obj3 = &new cmain(host, user, pass, db);
  194.     $obj4 = &new cmain(host, user, pass, db);
  195.    
  196.     $obj5 = &new cmain(host, user, pass, db);
  197.     $obj6 = &new cmain(host, user, pass, db);
  198.    
  199.     $obj7 = &new cmain(host, user, pass, db);
  200. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement