PDOStatement.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\DBAL\Driver;
  20. /**
  21. * The PDO implementation of the Statement interface.
  22. * Used by all PDO-based drivers.
  23. *
  24. * @since 2.0
  25. */
  26. class PDOStatement extends \PDOStatement implements Statement
  27. {
  28. /**
  29. * Protected constructor.
  30. */
  31. protected function __construct()
  32. {
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
  38. {
  39. // This thin wrapper is necessary to shield against the weird signature
  40. // of PDOStatement::setFetchMode(): even if the second and third
  41. // parameters are optional, PHP will not let us remove it from this
  42. // declaration.
  43. try {
  44. if ($arg2 === null && $arg3 === null) {
  45. return parent::setFetchMode($fetchMode);
  46. }
  47. if ($arg3 === null) {
  48. return parent::setFetchMode($fetchMode, $arg2);
  49. }
  50. return parent::setFetchMode($fetchMode, $arg2, $arg3);
  51. } catch (\PDOException $exception) {
  52. throw new PDOException($exception);
  53. }
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function bindValue($param, $value, $type = \PDO::PARAM_STR)
  59. {
  60. try {
  61. return parent::bindValue($param, $value, $type);
  62. } catch (\PDOException $exception) {
  63. throw new PDOException($exception);
  64. }
  65. }
  66. /**
  67. * {@inheritdoc}
  68. */
  69. public function bindParam($column, &$variable, $type = \PDO::PARAM_STR, $length = null, $driverOptions = null)
  70. {
  71. try {
  72. return parent::bindParam($column, $variable, $type, $length, $driverOptions);
  73. } catch (\PDOException $exception) {
  74. throw new PDOException($exception);
  75. }
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function execute($params = null)
  81. {
  82. try {
  83. return parent::execute($params);
  84. } catch (\PDOException $exception) {
  85. throw new PDOException($exception);
  86. }
  87. }
  88. /**
  89. * {@inheritdoc}
  90. */
  91. public function fetch($fetchMode = null, $cursorOrientation = null, $cursorOffset = null)
  92. {
  93. try {
  94. if ($fetchMode === null && $cursorOrientation === null && $cursorOffset === null) {
  95. return parent::fetch();
  96. }
  97. if ($cursorOrientation === null && $cursorOffset === null) {
  98. return parent::fetch($fetchMode);
  99. }
  100. if ($cursorOffset === null) {
  101. return parent::fetch($fetchMode, $cursorOrientation);
  102. }
  103. return parent::fetch($fetchMode, $cursorOrientation, $cursorOffset);
  104. } catch (\PDOException $exception) {
  105. throw new PDOException($exception);
  106. }
  107. }
  108. /**
  109. * {@inheritdoc}
  110. */
  111. public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
  112. {
  113. try {
  114. if ($fetchMode === null && $fetchArgument === null && $ctorArgs === null) {
  115. return parent::fetchAll();
  116. }
  117. if ($fetchArgument === null && $ctorArgs === null) {
  118. return parent::fetchAll($fetchMode);
  119. }
  120. if ($ctorArgs === null) {
  121. return parent::fetchAll($fetchMode, $fetchArgument);
  122. }
  123. return parent::fetchAll($fetchMode, $fetchArgument, $ctorArgs);
  124. } catch (\PDOException $exception) {
  125. throw new PDOException($exception);
  126. }
  127. }
  128. /**
  129. * {@inheritdoc}
  130. */
  131. public function fetchColumn($columnIndex = 0)
  132. {
  133. try {
  134. return parent::fetchColumn($columnIndex);
  135. } catch (\PDOException $exception) {
  136. throw new PDOException($exception);
  137. }
  138. }
  139. }