DriverException.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Doctrine\DBAL\Exception;
  3. use Doctrine\DBAL\DBALException;
  4. use Exception;
  5. /**
  6. * Base class for all errors detected in the driver.
  7. */
  8. class DriverException extends DBALException
  9. {
  10. /**
  11. * The previous DBAL driver exception.
  12. *
  13. * @var \Doctrine\DBAL\Driver\DriverException
  14. */
  15. private $driverException;
  16. /**
  17. * @param string $message The exception message.
  18. * @param \Doctrine\DBAL\Driver\DriverException $driverException The DBAL driver exception to chain.
  19. */
  20. public function __construct($message, \Doctrine\DBAL\Driver\DriverException $driverException)
  21. {
  22. $exception = null;
  23. if ($driverException instanceof Exception) {
  24. $exception = $driverException;
  25. }
  26. parent::__construct($message, 0, $exception);
  27. $this->driverException = $driverException;
  28. }
  29. /**
  30. * Returns the driver specific error code if given.
  31. *
  32. * Returns null if no error code was given by the driver.
  33. *
  34. * @return int|string|null
  35. */
  36. public function getErrorCode()
  37. {
  38. return $this->driverException->getErrorCode();
  39. }
  40. /**
  41. * Returns the SQLSTATE the driver was in at the time the error occurred, if given.
  42. *
  43. * Returns null if no SQLSTATE was given by the driver.
  44. *
  45. * @return string|null
  46. */
  47. public function getSQLState()
  48. {
  49. return $this->driverException->getSQLState();
  50. }
  51. }