| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace Models;
- class CprPreregistrationModel
- {
- private \PDO $pdo;
- public function __construct()
- {
- $dbFile = $_ENV['DB_FILE'];
- $dbPath = __DIR__ . '/../' . $dbFile;
- $this->pdo = new \PDO("sqlite:" . $dbPath);
- $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
- }
- public function insert(
- string $name,
- string $contactNumber,
- string $email,
- string $productType,
- string $internalControlNumber,
- int $productQuantity,
- string $propertyName,
- string $propertyLocation
- ): array {
- $stmt = $this->pdo->prepare(
- "INSERT INTO cpr_preregistration (
- name, contact_number, email, product_type, internal_control_number, product_quantity, property_name, property_location
- ) VALUES (
- :name, :contact_number, :email, :product_type, :internal_control_number, :product_quantity, :property_name, :property_location
- )"
- );
- $stmt->execute([
- 'name' => $name,
- 'contact_number' => $contactNumber,
- 'email' => $email,
- 'product_type' => $productType,
- 'internal_control_number' => $internalControlNumber,
- 'product_quantity' => $productQuantity,
- 'property_name' => $propertyName,
- 'property_location' => $propertyLocation,
- ]);
- $id = (int)$this->pdo->lastInsertId();
- $stmt = $this->pdo->prepare("SELECT * FROM cpr_preregistration WHERE cpr_id = :id");
- $stmt->execute(['id' => $id]);
- $row = $stmt->fetch(\PDO::FETCH_ASSOC);
- if (!$row) {
- throw new \RuntimeException('Failed to fetch inserted CPR pre-registration record');
- }
- return $row;
- }
- }
|