Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DB extends PDO
- {
- // объявление свойства
- protected $host = 'localhost';
- protected $db = 'dfgdfgdfgdfg'; // имя базы
- protected $charset = 'utf8';
- protected $user = 'dfgdfgdfg'; // имя юзера
- protected $pass = 'dfgdfgdfg'; // пароль юзера
- function __construct()
- {
- $dsn = "mysql:host=$this->host;dbname=$this->db;charset=$this->charset";
- $opt = [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- ];
- parent::__construct($dsn, $this->user, $this->pass, $opt);
- }
- public function checkDoubleMail($table, $column, $email) {
- // Проверим есть ли такой юзер
- $auth = $this->prepare('SELECT COUNT(*) FROM `'.$table.'` WHERE `'.$column.'`=:mail');
- $auth->bindParam(':'.$column, $email, PDO::PARAM_STR);
- $auth->execute();
- $Count = $auth->fetchAll();
- return intval(implode('', $Count[0]));
- }
- }
- class Validator extends DB
- {
- public function checkUnique($table, $column, $email)
- {
- $auth = $this->prepare('SELECT COUNT(*) FROM `'.$table.'` WHERE `'.$column.'`=:mail');
- $auth->bindParam(':'.$column, $email, PDO::PARAM_STR);
- $auth->execute();
- $Count = $auth->fetchAll();
- return intval(implode('', $Count[0]));
- }
- }
- $obj = new DB();
- echo '<pre>'; var_dump($obj); echo '</pre>';
- $val = new Validator($obj);
- $check = $val->checkUnique('users', 'mail', 'mail@yandex.ru');
- echo '<pre>'; var_dump($check); echo '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement