Advertisement
Guest User

Untitled

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