Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2.  
  3. class DB extends PDO
  4. {
  5.     // объявление свойства
  6.     protected $host = 'localhost';
  7.     protected $db =   'dfgdfgdfgdfg';  // имя базы
  8.     protected $charset = 'utf8';
  9.     protected $user = 'dfgdfgdfg';       //  имя юзера
  10.     protected $pass = 'dfgdfgdfg';  //  пароль юзера
  11.  
  12.     function __construct()
  13.     {
  14.         $dsn = "mysql:host=$this->host;dbname=$this->db;charset=$this->charset";
  15.         $opt = [
  16.             PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
  17.             PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  18.         ];
  19.         parent::__construct($dsn, $this->user, $this->pass, $opt);
  20.     }
  21.     public function checkDoubleMail($table, $column, $email) {
  22.         // Проверим есть ли такой юзер
  23.         $auth = $this->prepare('SELECT COUNT(*) FROM `'.$table.'` WHERE `'.$column.'`=:mail');
  24.         $auth->bindParam(':'.$column, $email, PDO::PARAM_STR);
  25.         $auth->execute();
  26.         $Count = $auth->fetchAll();
  27.         return intval(implode('', $Count[0]));
  28.     }
  29. }
  30.  
  31. class Validator extends DB
  32. {
  33.     public function checkUnique($table, $column, $email)
  34.     {
  35.         $auth = $this->prepare('SELECT COUNT(*) FROM `'.$table.'` WHERE `'.$column.'`=:mail');
  36.         $auth->bindParam(':'.$column, $email, PDO::PARAM_STR);
  37.         $auth->execute();
  38.         $Count = $auth->fetchAll();
  39.         return intval(implode('', $Count[0]));
  40.     }
  41. }
  42.  
  43. $obj = new DB();
  44. echo '<pre>'; var_dump($obj); echo '</pre>';
  45.  
  46. $val = new Validator($obj);
  47. $check = $val->checkUnique('users', 'mail', 'mail@yandex.ru');
  48. echo '<pre>'; var_dump($check); echo '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement