Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.92 KB | None | 0 0
  1. <?php
  2.  
  3.     class main
  4.     {
  5.         private $host = "localhost";
  6.         private $user = "root";
  7.         private $pass = "";
  8.         private $db   = "laboratory";
  9.  
  10.         private $insert_first = array();
  11.         private $insert_last = array();  
  12.        
  13.         private $update = array();
  14.        
  15.         public function __construct() {
  16.             $this->link = mysql_connect("$this->host","$this->user","$this->pass");
  17.             mysql_select_db($this->db,$this->link);
  18.         }
  19.        
  20.         public function insert($tbl,$data) {
  21.            
  22.             $this->tbl = $tbl;
  23.              
  24.             foreach ($this->data = $data as $name=>$value)
  25.             {
  26.                 $this->insert_first[] = $name;
  27.                 $this->insert_last[]= mysql_real_escape_string($value);
  28.  
  29.                 $this->results[$name] = $value;
  30.  
  31.             }
  32.  
  33.             $this->insert_first = '('.implode(',',$this->insert_first).')';
  34.             $this->insert_last = "('".implode("','",$this->insert_last)."')";
  35.  
  36.             mysql_query("INSERT INTO  $this->tbl $this->insert_first VALUES $this->insert_last ") or die (mysql_error());
  37.  
  38.             return ($this->results);
  39.         }
  40.        
  41.         public function update ($tbl,$uid,$data){
  42.             $this->tbl = $tbl;
  43.             $this->uid = $uid;
  44.                        
  45.             foreach ($this->data = $data as $name=>$value){
  46.                 $value = mysql_real_escape_string($value);
  47.                 $this->update[] = "$name = '$value'";
  48.             }
  49.            
  50.             $this->update  = implode (',',$this->update) ;
  51.            
  52.             mysql_query("UPDATE $this->tbl SET $this->update  WHERE id='$this->uid' ") or die (mysql_error());
  53.             echo ("UPDATE `$this->tbl` SET $this->update  WHERE id='$this->uid' ");
  54.         }
  55.        
  56.         public function select ($tbl,$uid){
  57.            
  58.             $this->tbl = $tbl;
  59.             $this->uid = $uid;
  60.            
  61.             if (empty($this->uid))
  62.                 $this->result = mysql_query("SELECT * FROM $this->tbl")or die (mysql_error());
  63.            
  64.             if (!empty($this->uid))
  65.                 $this->result = mysql_query("SELECT * FROM $this->tbl WHERE id='$this->uid'")or die (mysql_error());
  66.  
  67.            
  68.             $this->return = array () ;
  69.             while ($this->row = mysql_fetch_array( $this->result )) {
  70.                 $this->return [] = $this->row ;
  71.             }
  72.            
  73.             return ($this->return);
  74.         }
  75.        
  76.         public function delete($tbl,$data){
  77.             $this->tbl = $tbl;
  78.             $this->data = $data;
  79.             foreach ($this->data as $this->value=>$this->key)
  80.             {
  81.                 mysql_query("DELETE FROM $this->tbl WHERE id='$this->key'");
  82.             }
  83.         }
  84.        
  85.        
  86.  
  87.  
  88.         public function __destruct() {
  89.             mysql_close($this->link);
  90.         }
  91.     }
  92.  
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement