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; } }