diff options
author | Camil Staps | 2016-07-27 17:13:59 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-27 17:13:59 +0200 |
commit | ad0f8266354950852d7f899f9891da063ff981ff (patch) | |
tree | 94c5f6f90a84a56a794ad6f11ae0a8683b3c5731 /classes | |
parent | Class names start with a capital (diff) |
Document Model
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); } |