Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class connection
- {
- public $errors = array();
- private $password;
- private $db;
- function __construct()
- {
- include('../dba/dba.txt');
- $this->db = new mysqli('localhost', 'tynach_blog', $this->password, 'tynach_blog');
- $this->error();
- }
- private function error()
- {
- $errno = mysqli_errno($this->db);
- $error = $errno.': '.mysqli_error($this->db).'.';
- if ($errno != 0) {
- $this->errors[] = $error;
- return false;
- } else {
- return true;
- }
- }
- function select_userid($user)
- {
- $query = $this->db->prepare('SELECT user_id FROM user_info WHERE username = ?');
- $query->bind_param('s', $user);
- $query->execute();
- $query->bind_result($user_id);
- $query->fetch();
- $query->close();
- return $user_id;
- }
- function select_username($user)
- {
- $query = $this->db->prepare('SELECT username FROM user_info WHERE username = ?');
- $query->bind_param('s', $user);
- $query->execute();
- $query->bind_result($username);
- $query->fetch();
- $query->close();
- return $username;
- }
- function check_password($user_id, $password)
- {
- $query = $this->db->prepare('SELECT user_id, password FROM login_info WHERE user_id = ? AND password = SHA1( ? )');
- $query->bind_param('is', $user_id, $password);
- $query->execute();
- $query->bind_result($user, $pass);
- $query->fetch();
- $query->close();
- if ($pass != '') {
- return true;
- }
- return false;
- }
- function print_errors()
- {
- foreach ($this->errors as $error) {
- printp("Error: $error");
- }
- }
- function __destruct()
- {
- $test = $this->db->close();
- }
- }
- $db = new connection;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement