Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

39 lignes
831B

  1. <?php
  2. declare(strict_types=1);
  3. namespace Core;
  4. abstract class Repository
  5. {
  6. protected Database $database;
  7. protected string $table;
  8. protected string $primaryKey = 'id';
  9. public function __construct(Database $database)
  10. {
  11. $this->database = $database;
  12. }
  13. public function find(int|string $id): ?array
  14. {
  15. return $this->database->first(
  16. "SELECT * FROM {$this->table} WHERE {$this->primaryKey} = :id",
  17. ['id' => $id]
  18. );
  19. }
  20. public function all(): array
  21. {
  22. return $this->database->query("SELECT * FROM {$this->table}");
  23. }
  24. public function delete(int|string $id): bool
  25. {
  26. return $this->database->execute(
  27. "DELETE FROM {$this->table} WHERE {$this->primaryKey} = :id",
  28. ['id' => $id]
  29. );
  30. }
  31. }

Powered by TurnKey Linux.