DescriptionModel.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 $productId, int $companyId, string $text): bool
  26. {
  27. $stmt = $this->pdo->prepare("UPDATE description SET description_text = :text WHERE product_id = :product_id AND company_id = :company_id");
  28. return $stmt->execute([
  29. 'text' => $text,
  30. 'product_id' => $productId,
  31. 'company_id' => $companyId,
  32. ]);
  33. }
  34. }