can you help me? I'm getting a little problems with my script.
database.php
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;
}
}
user.php
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();
}
The script isn't working! I'm getting Call to a member function prepare() on a non-object on line 16
= $STH = $this->DBH->prepare("INSERT INTO
phppdoVALUES(NULL, :username, :email, UNIX_TIMESTAMP())");
I don't know why it's happening... Can you help me? Thank you!!