Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class prepared
- {
- public $statement;
- public $par;
- function __construct($query, $par)
- {
- $this->par = $par;
- $this->statement = $this->par->db->prepare($query);
- }
- function __destruct()
- {
- $this->statement->close();
- }
- function __call($func, $args)
- {
- return call_user_func_array(array($this->statement, $func), $args);
- }
- }
- class connection
- {
- public $errors = array();
- public $password;
- public $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 prepare($query, $name)
- {
- if ($this->db AND !$this->name) {
- $this->$name = new prepared($query, $this);
- return true;
- } else {
- return false;
- }
- }
- function select_userid($user)
- {
- $name = 'user';
- $this->prepare('SELECT user_id FROM user_info WHERE username = ?', $name);
- $this->$name->bind_param('s', $user);
- $this->$name->execute();
- $this->$name->bind_result($user_id);
- $this->$name->fetch();
- 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