Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Database {
- protected $host = "localhost";
- protected $dbname = "phppdo";
- protected $user = "root";
- protected $pass = "";
- protected $DBH;
- public function __construct() {
- try {
- $this->DBH = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->pass);
- }
- catch (PDOException $e) {
- die($e->getMessage());
- }
- return $this->DBH;
- }
- }
- date_default_timezone_set('America/Sao_Paulo');
- include 'database.php';
- class User extends Database {
- private $name;
- private $email;
- private $date;
- function __construct($name, $email) {
- $this->$name = $name;
- $this->$email = $email;
- }
- public function insert() {
- $STH = $this->DBH->prepare("INSERT INTO `phppdo` VALUES(NULL, :username, :email, UNIX_TIMESTAMP())");
- $STH->execute(array(
- ':name' => $name,
- ':emal' => $email,
- ));
- }
- }
- if(isset($_POST['submit'])) {
- $x = new User($_POST['name'], $_POST['email']);
- $x->insert();
- }
Add Comment
Please, Sign In to add comment