HarvestModel.php 563 B

1234567891011121314151617181920212223
  1. <?php
  2. namespace Models;
  3. class HarvestModel
  4. {
  5. private \PDO $pdo;
  6. public function __construct()
  7. {
  8. if (!isset($GLOBALS['pdo']) || !$GLOBALS['pdo'] instanceof \PDO) {
  9. throw new \RuntimeException('Global PDO connection not initialized');
  10. }
  11. $this->pdo = $GLOBALS['pdo'];
  12. }
  13. public function getAll(): array
  14. {
  15. $stmt = $this->pdo->query('SELECT harvest_code, harvest_name FROM "harvest" ORDER BY harvest_name');
  16. return $stmt->fetchAll(\PDO::FETCH_ASSOC) ?: [];
  17. }
  18. }