Exemple #1
0
 public static function emailFind($email)
 {
     $db = Database::connect();
     //TODO: Change to prepared statement
     if ($stmt = $db->query("SELECT id FROM Users WHERE email = '{$email}'")) {
         if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
             return new self($data["id"]);
         } else {
             //No user with that email
             return false;
         }
     } else {
         throw \Exception\DatabaseError::build($db);
     }
 }
Exemple #2
0
 public function delete()
 {
     $db = Database::connect();
     if ($stmt = $db->prepare("DELETE FROM {$this->table} WHERE id=:id LIMIT 1;")) {
         $stmt->bindParam(":id", $this->id);
         if ($stmt->execute()) {
             foreach ($this->getPublicProperties() as $p) {
                 $this->{$p} = null;
             }
             return true;
         } else {
             throw \Exception\DatabaseError::build($stmt);
         }
     } else {
         throw \Exception\DatabaseError::build($db);
     }
 }