Advertisement
Guest User

Untitled

a guest
Aug 30th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2. class DB {
  3.     public $fields = array();
  4.     private $username = 'promoGuy';
  5.     private $hostname = 'localhost';
  6.     private $password = 'Qk0AN581Ll';
  7.     private $database = 'register_shell';
  8.    
  9.     private $link = null;
  10.    
  11.     public function __construct() {
  12.         if (!$this->getLink()) {
  13.             $this->connect();
  14.         }
  15.     }
  16.  
  17.     public function getLink() {
  18.         return $this->link;
  19.     }
  20.  
  21.     public function connect() {
  22.         $this->link = mysqli_connect($this->hostname, $this->username, $this->password);
  23.         if ($this->link) {
  24.             mysqli_select_db($this->link, $this->database);
  25.             mysqli_query($this->link, 'SET NAMES utf8');
  26.             mysqli_set_charset($this->link, 'utf8');
  27.             return $this->database;
  28.         } else {
  29.             print "MySQL Error connecting"; exit;
  30.         }
  31.        
  32.     }
  33.  
  34.     public function insert($columns = array(), $variables = array()) {
  35.         $query = $this->prepareQuery();
  36.         $result = $this->executeQuery($query, 'insert');
  37.     }
  38.  
  39.     public function delete($columns = array(), $variables = array(), $where) {
  40.         $query = $this->prepareQuery();
  41.         $result = $this->executeQuery($query, 'delete');
  42.     }
  43.  
  44.     public function update($columns = array(), $variables = array(), $where) {
  45.         $query = $this->prepareQuery();
  46.         $result = $this->executeQuery($query, 'update');
  47.     }
  48.  
  49.     public function select($what, $where) {
  50.        
  51.     }
  52.  
  53.     private function prepareQuery($queryType, $columns = array(), $variables = array(), $where = null) {
  54.        
  55.     }
  56.  
  57.     public function sanitizeVariables($variables = array()) {
  58.         // mysql_real_escape_string()
  59.         $sanitized = array();
  60.         foreach($variables as $key => $value) {
  61.             $sanitized[$key] = urldecode(mysqli_real_escape_string($value));
  62.         }
  63.        
  64.         return $sanitized;
  65.     }
  66.  
  67.     private function executeQuery($query, $type) {
  68.  
  69.         // mysql_affected_rows();
  70.         // mysql_insert_id();
  71.         $error = '';
  72.         mysqli_query($query) or $error = mysqli_error();
  73.         if ($error != '') {
  74.             return $error;
  75.         }
  76.        
  77.         if ($type == 'insert') {
  78.             return mysqli_insert_id();
  79.         } else {
  80.             return mysqli_affected_rows();
  81.         }
  82.     }
  83. }
  84.  
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement