Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Doctrine\DBAL\Driver;
  4.  
  5. use Doctrine\DBAL\ParameterType;
  6. use PDO;
  7. use function count;
  8. use function func_get_args;
  9.  
  10. /**
  11. * PDO implementation of the Connection interface.
  12. * Used by all PDO-based drivers.
  13. */
  14. class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
  15. {
  16. /**
  17. * @param string $dsn
  18. * @param string|null $user
  19. * @param string|null $password
  20. * @param mixed[]|null $options
  21. *
  22. * @throws PDOException In case of an error.
  23. */
  24. public function __construct($dsn, $user = null, $password = null, ?array $options = null)
  25. {
  26. try {
  27. parent::__construct($dsn, $user, $password, $options);
  28. $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]);
  29. $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  30. } catch (\PDOException $exception) {
  31. throw new PDOException($exception);
  32. }
  33. }
  34.  
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function exec($statement)
  39. {
  40. try {
  41. return parent::exec($statement);
  42. } catch (\PDOException $exception) {
  43. throw new PDOException($exception);
  44. }
  45. }
  46.  
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function getServerVersion()
  51. {
  52. return PDO::getAttribute(PDO::ATTR_SERVER_VERSION);
  53. }
  54.  
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function prepare($prepareString, $driverOptions = [])
  59. {
  60. try {
  61. return parent::prepare($prepareString, $driverOptions);
  62. } catch (\PDOException $exception) {
  63. throw new PDOException($exception);
  64. }
  65. }
  66.  
  67. /**
  68. * {@inheritdoc}
  69. */
  70. public function query()
  71. {
  72. $args = func_get_args();
  73. $argsCount = count($args);
  74.  
  75. try {
  76. if ($argsCount === 4) {
  77. return parent::query($args[0], $args[1], $args[2], $args[3]);
  78. }
  79.  
  80. if ($argsCount === 3) {
  81. return parent::query($args[0], $args[1], $args[2]);
  82. }
  83.  
  84. if ($argsCount === 2) {
  85. return parent::query($args[0], $args[1]);
  86. }
  87.  
  88. return parent::query($args[0]);
  89. } catch (\PDOException $exception) {
  90. throw new PDOException($exception);
  91. }
  92. }
  93.  
  94. /**
  95. * {@inheritdoc}
  96. */
  97. public function quote($input, $type = ParameterType::STRING)
  98. {
  99. return parent::quote($input, $type);
  100. }
  101.  
  102. /**
  103. * {@inheritdoc}
  104. */
  105. public function lastInsertId($name = null)
  106. {
  107. try {
  108. return parent::lastInsertId($name);
  109. } catch (\PDOException $exception) {
  110. throw new PDOException($exception);
  111. }
  112. }
  113.  
  114. /**
  115. * {@inheritdoc}
  116. */
  117. public function requiresQueryForServerVersion()
  118. {
  119. return false;
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement