diff options
| author | Syndamia <kamen@syndamia.com> | 2025-01-19 19:24:34 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2025-01-19 19:24:34 +0200 |
| commit | eeca9f447abbecb5e2173154499a3cd7f75977ea (patch) | |
| tree | 459c717c555df9a5aba36d7632b2c55ab9702d8a /models | |
| parent | 658fd289774d658347ccc5eafa5c140b8ff48d39 (diff) | |
| download | nowayforward_human-eeca9f447abbecb5e2173154499a3cd7f75977ea.tar nowayforward_human-eeca9f447abbecb5e2173154499a3cd7f75977ea.tar.gz nowayforward_human-eeca9f447abbecb5e2173154499a3cd7f75977ea.zip | |
feat(database): Add an update record function
Diffstat (limited to 'models')
| -rw-r--r-- | models/database.php | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/models/database.php b/models/database.php index 1fe05e0..45be65b 100644 --- a/models/database.php +++ b/models/database.php @@ -1,6 +1,7 @@ <?php namespace Database; use PDO; +use Exception; abstract class Table { // Cannot be created, because FETCH_CLASS will assign to all attributes @@ -16,7 +17,7 @@ abstract class Table { if ($query->rowCount() == 0) { throw new Exception("Value for $class doesn't exist!"); } - assert($query->rowCount() == 1, "Vaue for $class must be uniqely specified!"); + assert($query->rowCount() == 1, "Value for $class must be uniqely specified!"); $query->setFetchMode(PDO::FETCH_CLASS, $class); return $query->fetch(); @@ -32,6 +33,12 @@ abstract class Table { return $id; } + static protected function _update(string $table, string $sets, string $identify) { + $conn = Table::connect(); + $query = $conn->query("UPDATE $table SET $sets WHERE $identify"); + $conn = null; + } + static protected function _get_all(string $table, string $class, string $additional = null) : array { $conn = Table::connect(); $query = $conn->query("SELECT * FROM $table " . $additional); |
