Advertisement
Guest User

Untitled

a guest
Oct 1st, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <?php
  2. class prepared
  3. {
  4.     public $statement;
  5.     public $par;
  6.  
  7.     function __construct($query, $par)
  8.     {
  9.         $this->par = $par;
  10.         $this->statement = $this->par->db->prepare($query);
  11.     }
  12.    
  13.     function __destruct()
  14.     {
  15.         $this->statement->close();
  16.     }
  17.  
  18.     function __call($func, $args)
  19.     {
  20.         return call_user_func_array(array($this->statement, $func), $args);
  21.     }
  22. }
  23.  
  24. class connection
  25. {
  26.     public $errors = array();
  27.     public $password;
  28.     public $db;
  29.  
  30.     function __construct()
  31.     {
  32.         include('../dba/dba.txt');
  33.         $this->db = new mysqli('localhost', 'tynach_blog', $this->password, 'tynach_blog');
  34.  
  35.         $this->error();
  36.     }
  37.  
  38.     private function error()
  39.     {
  40.         $errno = mysqli_errno($this->db);
  41.         $error = $errno.': '.mysqli_error($this->db).'.';
  42.         if ($errno != 0) {
  43.             $this->errors[] = $error;
  44.             return false;
  45.         } else {
  46.             return true;
  47.         }
  48.     }
  49.  
  50.     function prepare($query, $name)
  51.     {
  52.         if ($this->db AND !$this->name) {
  53.             $this->$name = new prepared($query, $this);
  54.             return true;
  55.         } else {
  56.             return false;
  57.         }
  58.     }
  59.    
  60.     function select_userid($user)
  61.     {
  62.         $name = 'user';
  63.         $this->prepare('SELECT user_id FROM user_info WHERE username = ?', $name);
  64.         $this->$name->bind_param('s', $user);
  65.         $this->$name->execute();
  66.         $this->$name->bind_result($user_id);
  67.         $this->$name->fetch();
  68.        
  69.         return $user_id;
  70.     }
  71.  
  72.     function select_username($user)
  73.     {
  74.         $query = $this->db->prepare('SELECT username FROM user_info WHERE username = ?');
  75.         $query->bind_param('s', $user);
  76.         $query->execute();
  77.         $query->bind_result($username);
  78.         $query->fetch();
  79.         $query->close();
  80.        
  81.         return $username;
  82.     }
  83.  
  84.     function check_password($user_id, $password)
  85.     {
  86.         $query = $this->db->prepare('SELECT user_id, password FROM login_info WHERE user_id = ? AND password = SHA1( ? )');
  87.         $query->bind_param('is', $user_id, $password);
  88.         $query->execute();
  89.         $query->bind_result($user, $pass);
  90.         $query->fetch();
  91.         $query->close();
  92.  
  93.         if ($pass != '') {
  94.             return true;
  95.         }
  96.         return false;
  97.     }
  98.  
  99.     function print_errors()
  100.     {
  101.         foreach ($this->errors as $error) {
  102.             printp("Error: $error");
  103.         }
  104.     }
  105.  
  106.     function __destruct()
  107.     {
  108.         $test = $this->db->close();
  109.     }
  110. }
  111.  
  112. $db = new connection;
  113. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement