DescriptionModel.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Models;
  3. class DescriptionModel
  4. {
  5. private \PDO $pdo;
  6. public function __construct()
  7. {
  8. $dbFile = $_ENV['DB_FILE'];
  9. $dbPath = __DIR__ . '/../' . $dbFile;
  10. $this->pdo = new \PDO("sqlite:" . $dbPath);
  11. $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
  12. }
  13. public function addDescription(int $productId, int $companyId, string $text): bool
  14. {
  15. $stmt = $this->pdo->prepare("
  16. INSERT INTO description (description_text, product_id, company_id)
  17. VALUES (:text, :product_id, :company_id)
  18. ");
  19. return $stmt->execute([
  20. 'text' => $text,
  21. 'product_id' => $productId,
  22. 'company_id' => $companyId,
  23. ]);
  24. }
  25. public function updateDescription(int $descriptionId, string $text): bool
  26. {
  27. $stmt = $this->pdo->prepare("
  28. UPDATE description SET description_text = :text
  29. WHERE description_id = :id
  30. ");
  31. return $stmt->execute([
  32. 'text' => $text,
  33. 'id' => $descriptionId,
  34. ]);
  35. }
  36. }