Guest User

Untitled

a guest
Mar 13th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', '1');
  3. error_reporting(E_ALL);
  4.  
  5.  
  6. class Db {
  7. private $host;
  8. private $db;
  9. private $user;
  10. private $pass;
  11. private $charset;
  12.  
  13. public function __construct()
  14. {
  15. $this->host = 'localhost';
  16. $this->db = 'exam';
  17. $this->user = 'root';
  18. $this->pass = 'root';
  19. $this-> charset = 'utf8';
  20. }
  21. public function dbConnect()
  22. {
  23. $dsn = "mysql:host=$this->host;dbname=$this->db;charset=$this->charset";
  24. $opt = [
  25. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  26. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  27. PDO::ATTR_EMULATE_PREPARES => false,
  28. ];
  29. $this->pdo = new PDO($dsn, $this->user, $this->pass, $opt);
  30. }
  31. public function insert()
  32. {
  33. $stmt = $this->pdo->prepare('INSERT INTO request SET mail = :mail, telephone = :telephone,fio_user = :fio_user, message=:message');
  34. $result = $stmt->execute(array('mail'=>$_POST['mail'],'telephone'=>$_POST['telephone'],'fio_user'=>$_POST['fio_user'], 'message'=>$_POST['message']));
  35. return $result;
  36. }
  37.  
  38. }
  39. ?>
Add Comment
Please, Sign In to add comment