Guest User

Untitled

a guest
Oct 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. class Database {
  2.  
  3. protected $host = "localhost";
  4. protected $dbname = "phppdo";
  5. protected $user = "root";
  6. protected $pass = "";
  7. protected $DBH;
  8.  
  9. public function __construct() {
  10. try {
  11. $this->DBH = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->pass);
  12. }
  13. catch (PDOException $e) {
  14. die($e->getMessage());
  15. }
  16. return $this->DBH;
  17. }
  18. }
  19.  
  20. date_default_timezone_set('America/Sao_Paulo');
  21. include 'database.php';
  22. class User extends Database {
  23.  
  24. private $name;
  25. private $email;
  26. private $date;
  27.  
  28. function __construct($name, $email) {
  29. $this->$name = $name;
  30. $this->$email = $email;
  31. }
  32.  
  33. public function insert() {
  34. $STH = $this->DBH->prepare("INSERT INTO `phppdo` VALUES(NULL, :username, :email, UNIX_TIMESTAMP())");
  35. $STH->execute(array(
  36. ':name' => $name,
  37. ':emal' => $email,
  38. ));
  39. }
  40. }
  41.  
  42. if(isset($_POST['submit'])) {
  43. $x = new User($_POST['name'], $_POST['email']);
  44. $x->insert();
  45. }
Add Comment
Please, Sign In to add comment