| | |
| | | abstract class Model |
| | | { |
| | | protected ?string $table; |
| | | public function __construct(private Database $database) { |
| | | |
| | | private function getTable() { |
| | | $parts = explode("\\", $this::class); |
| | | return strtolower(array_pop($parts)); |
| | | } |
| | | public function __construct(private Database $database) { |
| | | } |
| | | public function findAll(): array|bool |
| | | { |
| | | $pdo = $this->database->getConnection(); |
| | | |
| | | $sql = "SELECT * FROM {$this->table}"; |
| | | $sql = "SELECT * FROM {$this->getTable()}"; |
| | | |
| | | $stmt = $pdo->query($sql); |
| | | |
| | |
| | | public function find(string $id) { |
| | | $conn = $this->database->getConnection(); |
| | | $sql = "SELECT * |
| | | FROM {$this->table} |
| | | FROM {$this->getTable()} |
| | | WHERE id = :id"; |
| | | $stmt = $conn->prepare($sql); |
| | | $stmt->bindValue(":id", $id, PDO::PARAM_INT); |