daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Jun 18th, 2017 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class User {
  3.    
  4.     public $id;
  5.     public $username;
  6.     public $password;
  7.     public $status;
  8.     public $lang;
  9.     public $privacy;
  10.     public $last_login;
  11.     public $is_admin;
  12.     public $create_date;
  13.  
  14.     private $DB;
  15.    
  16.     public function __construct($id=0)
  17.     {
  18.         $this->DB = Database::getInstance(); //Database yönetim class'ın olduğunu varsayalım..
  19.         if ($id > 0)
  20.             $this->load($id);
  21.     }
  22.    
  23.     public function load($id)
  24.     {
  25.         $id = floatval($id);
  26.         $get = $this->DB->getRows("SELECT * FROM users WHERE id = ".$id);
  27.         if (count($get)>0)
  28.         {
  29.             $find = $get[0];
  30.            
  31.             $this->id       = $find['id'];
  32.             $this->username     = $find['username'];
  33.             $this->password     = $find['password'];
  34.             $this->status       = $find['status'];
  35.             $this->is_admin     = $find['is_admin'];
  36.             $this->lang     = $find['lang'];
  37.             $this->privacy      = $find['privacy'];
  38.             $this->last_login   = $find['last_login'];
  39.             $this->create_date  = $find['create_date'];
  40.            
  41.         } else {
  42.             return false;
  43.         }
  44.     }
  45.    
  46.     public function save()
  47.     {
  48.         if ($this->id > 0)
  49.         {
  50.             $sql = "UPDATE users SET ";
  51.             $sql.= "username = '".$this->DB->sqlTemizle($this->username)."', ";
  52.             $sql.= "password = '".$this->DB->sqlTemizle($this->password)."', ";
  53.             $sql.= "status = ".floatval($this->status).", ";
  54.             $sql.= "is_admin = ".floatval($this->is_admin).", ";
  55.             $sql.= "lang = '".$this->DB->sqlTemizle($this->lang)."', ";
  56.             $sql.= "privacy = ".floatval($this->privacy).", ";
  57.             $sql.= "last_login = '".$this->DB->sqlTemizle($this->last_login)."', ";
  58.             $sql.= "create_date = '".$this->DB->sqlTemizle($this->create_date)."'";
  59.             $sql.= " WHERE id = ".$this->id;
  60.            
  61.             $this->DB->query($sql);
  62.            
  63.         } else {
  64.            
  65.             $sql = "INSERT INTO users SET ";
  66.             $sql.= "username = '".$this->DB->sqlTemizle($this->username)."', ";
  67.             $sql.= "password = '".$this->DB->sqlTemizle($this->password)."', ";
  68.             $sql.= "status = ".floatval($this->status).", ";
  69.             $sql.= "is_admin = ".floatval($this->is_admin).", ";
  70.             $sql.= "lang = '".$this->DB->sqlTemizle($this->lang)."', ";
  71.             $sql.= "privacy = ".floatval($this->privacy).", ";
  72.             $sql.= "last_login = '".$this->DB->sqlTemizle($this->last_login)."', ";
  73.             $sql.= "create_date = '".$this->DB->sqlTemizle($this->create_date)."'";
  74.  
  75.             $this->DB->query($sql);
  76.             $this->load($this->DB->getLastInsertId());
  77.         }
  78.     }
  79. }
  80.  
  81. //kullanımı
  82.  
  83. $user = new User;
  84. $user->username = $_POST['username'];
  85. $user->password = $_POST['password'];
  86. //...
  87. $new_user = $user->save();
  88.  
  89. //oluşan userin ID'sini almak için
  90. echo $new_user->id;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top