Firebird.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Pdo;
  11. if (\PHP_VERSION_ID < 80400 && \extension_loaded('pdo_firebird')) {
  12. class Firebird extends \PDO
  13. {
  14. public const ATTR_DATE_FORMAT = \PDO::FB_ATTR_DATE_FORMAT;
  15. public const ATTR_TIME_FORMAT = \PDO::FB_ATTR_TIME_FORMAT;
  16. public const ATTR_TIMESTAMP_FORMAT = \PDO::FB_ATTR_TIMESTAMP_FORMAT;
  17. public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null)
  18. {
  19. parent::__construct($dsn, $username, $password, $options);
  20. if ('firebird' !== $driver = $this->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
  21. throw new \PDOException(\sprintf('Pdo\Firebird::__construct() cannot be used for connecting to the "%s" driver', $driver));
  22. }
  23. }
  24. public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self
  25. {
  26. try {
  27. return new self($dsn, $username, $password, $options);
  28. } catch (\PDOException $e) {
  29. throw preg_match('/^Pdo\\\\Firebird::__construct\(\) cannot be used for connecting to the "([a-z]+)" driver/', $e->getMessage(), $matches) ? new \PDOException(\sprintf('Pdo\Firebird::connect() cannot be used for connecting to the "%s" driver', $matches[1])) : $e;
  30. }
  31. }
  32. }
  33. }