PDOException.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Doctrine\DBAL\Driver;
  3. /**
  4. * Tiny wrapper for PDOException instances to implement the {@link DriverException} interface.
  5. */
  6. class PDOException extends \PDOException implements DriverException
  7. {
  8. /**
  9. * The driver specific error code.
  10. *
  11. * @var int|string|null
  12. */
  13. private $errorCode;
  14. /**
  15. * The SQLSTATE of the driver.
  16. *
  17. * @var string|null
  18. */
  19. private $sqlState;
  20. /**
  21. * @param \PDOException $exception The PDO exception to wrap.
  22. */
  23. public function __construct(\PDOException $exception)
  24. {
  25. parent::__construct($exception->getMessage(), 0, $exception);
  26. $this->code = $exception->getCode();
  27. $this->errorInfo = $exception->errorInfo;
  28. $this->errorCode = $exception->errorInfo[1] ?? $exception->getCode();
  29. $this->sqlState = $exception->errorInfo[0] ?? $exception->getCode();
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function getErrorCode()
  35. {
  36. return $this->errorCode;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function getSQLState()
  42. {
  43. return $this->sqlState;
  44. }
  45. }