diff options
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Model.php | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/classes/Model.php b/classes/Model.php index 68f045e..3e99856 100644 --- a/classes/Model.php +++ b/classes/Model.php @@ -55,13 +55,22 @@ abstract class Model { */ protected $pdo, $data; + /** + * Create a new instance + * + * @param PDO $pdo The PDO class, to access the database + * @param int $id The id of the row to fetch + * + * @throws PDOException If something went wrong with the database + * @throws ModelNotFoundException If the id could not be found + */ public function __construct($pdo, $id) { $this->pdo = $pdo; $stmt = $this->pdo->prepare("SELECT * FROM `".$this->table()."` WHERE `{$this->primary_key}`=?"); $stmt->execute([$id]); if ($stmt->rowCount() == 0) { - throw new Exception("The {$this->table} with id '$id' could not be found."); + throw new ModelNotFoundException("The {$this->table} with id '$id' could not be found."); } $this->data = $stmt->fetch(PDO::FETCH_ASSOC); } |