Guest User

Untitled

a guest
Mar 13th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2. class Connect
  3. {
  4.  
  5. private $user;
  6. private $pass;
  7. private $host;
  8. private $db;
  9. private $dsn;
  10. private $pdo;
  11. public function __construct($userName, $userPassword, $host, $db)
  12. {
  13. $opt=array(
  14. PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,
  15. PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC
  16. );
  17. $this->user = $userName;
  18. $this->pass = $userPassword;
  19. $this->host = $host;
  20. $this->db = $db;
  21. $this->pdo = new PDO($this->settings(), $userName, $userPassword,$opt);
  22. }
  23. public function getUserName()
  24. {
  25. return $this->user;
  26. }
  27. public function getPass()
  28. {
  29. return $this->pass;
  30. }
  31. public function getHost()
  32. {
  33. return $this->host;
  34. }
  35. public function getDataBase()
  36. {
  37. return $this->db;
  38. }
  39. public function settings()
  40. {
  41. $this->dsn = "mysql:host={$this->host};dbname={$this->db}";
  42. return $this->dsn;
  43. }
  44.  
  45. public function insert($password, $login,$surname,$name,$phone=null,$sex)
  46. {
  47. $sql='INSERT INTO users SET password = ?, login = ?, surname = ?, name = ?, phone = ?, sex = ?';
  48. return $this->pdo()->prepare($sql)->execute(array($password, $login,$surname,$name,$phone,$sex));
  49. }
  50.  
  51. }
  52. ?>
Add Comment
Please, Sign In to add comment