Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Connect
- {
- private $user;
- private $pass;
- private $host;
- private $db;
- private $dsn;
- private $pdo;
- public function __construct($userName, $userPassword, $host, $db)
- {
- $opt=array(
- PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC
- );
- $this->user = $userName;
- $this->pass = $userPassword;
- $this->host = $host;
- $this->db = $db;
- $this->pdo = new PDO($this->settings(), $userName, $userPassword,$opt);
- }
- public function getUserName()
- {
- return $this->user;
- }
- public function getPass()
- {
- return $this->pass;
- }
- public function getHost()
- {
- return $this->host;
- }
- public function getDataBase()
- {
- return $this->db;
- }
- public function settings()
- {
- $this->dsn = "mysql:host={$this->host};dbname={$this->db}";
- return $this->dsn;
- }
- public function insert($password, $login,$surname,$name,$phone=null,$sex)
- {
- $sql='INSERT INTO users SET password = ?, login = ?, surname = ?, name = ?, phone = ?, sex = ?';
- return $this->pdo()->prepare($sql)->execute(array($password, $login,$surname,$name,$phone,$sex));
- }
- }
- ?>
Add Comment
Please, Sign In to add comment