<?php
class SppUser {
private $uid; //user id
private $fields;
private $_db; //holds PDO;
private $db_user;
private $db_pass;
public function __construct() {
$this->db_user = "root";
$this->db_pass = "";
$this->uid;
'username' => '',
'password' => '',
'email' => '');
try {
$this->_db = new PDO("mysql:host=localhost;dbname=spp", $this->db_user, $this->db_pass);
} catch (Exception $exc) {
echo $exc->getMessage();
}
}
//Registry pattern via magical methods __get and __set
public function __set($field, $value) {
$this->fields[$field] = $value;
}
public function __get($field) {
return $this->fields[$field];
}
// key does not exist, either return a default
return null;
// or throw an exception
throw new OutOfBoundsException($fields);
}
//saving use in a database via prepared statements
public function save() {
$stmt = $this->_db->prepare("INSERT INTO users( user_id,username, password, email)
VALUES(:user_id,:username,:password, :email)");
try {
':user_id' => $this->uid,
':username' => $this->username,
':password' => $this->password,
':email' => $this->email));
} catch (Exception $exc) {
echo $exc->getMessage();
}
}
public function login()
{
$stmt=$this->_db->prepare("SELECT username, password FROM users WHERE username= :username
AND password= :password");
":username"=>$this->username,
":password"=>$this->password));
if($stmt->rowCount() >0 )
{
$_SESSION['username'] = $this->username;
header("Location: profile.php"); }
else
{
//new exdasa
}
}
}
?>