Statement.php 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information, see
  19. * <http://www.doctrine-project.org>.
  20. */
  21. namespace Doctrine\DBAL\Driver;
  22. use \PDO;
  23. /**
  24. * Statement interface.
  25. * Drivers must implement this interface.
  26. *
  27. * This resembles (a subset of) the PDOStatement interface.
  28. *
  29. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
  30. * @author Roman Borschel <roman@code-factory.org>
  31. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  32. * @link www.doctrine-project.org
  33. * @since 2.0
  34. * @version $Revision$
  35. */
  36. interface Statement
  37. {
  38. /**
  39. * Binds a value to a corresponding named or positional
  40. * placeholder in the SQL statement that was used to prepare the statement.
  41. *
  42. * @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
  43. * this will be a parameter name of the form :name. For a prepared statement
  44. * using question mark placeholders, this will be the 1-indexed position of the parameter
  45. *
  46. * @param mixed $value The value to bind to the parameter.
  47. * @param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants.
  48. *
  49. * @return boolean Returns TRUE on success or FALSE on failure.
  50. */
  51. function bindValue($param, $value, $type = null);
  52. /**
  53. * Binds a PHP variable to a corresponding named or question mark placeholder in the
  54. * SQL statement that was use to prepare the statement. Unlike PDOStatement->bindValue(),
  55. * the variable is bound as a reference and will only be evaluated at the time
  56. * that PDOStatement->execute() is called.
  57. *
  58. * Most parameters are input parameters, that is, parameters that are
  59. * used in a read-only fashion to build up the query. Some drivers support the invocation
  60. * of stored procedures that return data as output parameters, and some also as input/output
  61. * parameters that both send in data and are updated to receive it.
  62. *
  63. * @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
  64. * this will be a parameter name of the form :name. For a prepared statement
  65. * using question mark placeholders, this will be the 1-indexed position of the parameter
  66. *
  67. * @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter.
  68. *
  69. * @param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants. To return
  70. * an INOUT parameter from a stored procedure, use the bitwise OR operator to set the
  71. * PDO::PARAM_INPUT_OUTPUT bits for the data_type parameter.
  72. * @return boolean Returns TRUE on success or FALSE on failure.
  73. */
  74. function bindParam($column, &$variable, $type = null);
  75. /**
  76. * Closes the cursor, enabling the statement to be executed again.
  77. *
  78. * @return boolean Returns TRUE on success or FALSE on failure.
  79. */
  80. function closeCursor();
  81. /**
  82. * columnCount
  83. * Returns the number of columns in the result set
  84. *
  85. * @return integer Returns the number of columns in the result set represented
  86. * by the PDOStatement object. If there is no result set,
  87. * this method should return 0.
  88. */
  89. function columnCount();
  90. /**
  91. * errorCode
  92. * Fetch the SQLSTATE associated with the last operation on the statement handle
  93. *
  94. * @see Doctrine_Adapter_Interface::errorCode()
  95. * @return string error code string
  96. */
  97. function errorCode();
  98. /**
  99. * errorInfo
  100. * Fetch extended error information associated with the last operation on the statement handle
  101. *
  102. * @see Doctrine_Adapter_Interface::errorInfo()
  103. * @return array error info array
  104. */
  105. function errorInfo();
  106. /**
  107. * Executes a prepared statement
  108. *
  109. * If the prepared statement included parameter markers, you must either:
  110. * call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
  111. * bound variables pass their value as input and receive the output value,
  112. * if any, of their associated parameter markers or pass an array of input-only
  113. * parameter values
  114. *
  115. *
  116. * @param array $params An array of values with as many elements as there are
  117. * bound parameters in the SQL statement being executed.
  118. * @return boolean Returns TRUE on success or FALSE on failure.
  119. */
  120. function execute($params = null);
  121. /**
  122. * fetch
  123. *
  124. * @see Query::HYDRATE_* constants
  125. * @param integer $fetchStyle Controls how the next row will be returned to the caller.
  126. * This value must be one of the Query::HYDRATE_* constants,
  127. * defaulting to Query::HYDRATE_BOTH
  128. *
  129. * @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor,
  130. * this value determines which row will be returned to the caller.
  131. * This value must be one of the Query::HYDRATE_ORI_* constants, defaulting to
  132. * Query::HYDRATE_ORI_NEXT. To request a scrollable cursor for your
  133. * PDOStatement object,
  134. * you must set the PDO::ATTR_CURSOR attribute to Doctrine::CURSOR_SCROLL when you
  135. * prepare the SQL statement with Doctrine_Adapter_Interface->prepare().
  136. *
  137. * @param integer $cursorOffset For a PDOStatement object representing a scrollable cursor for which the
  138. * $cursorOrientation parameter is set to Query::HYDRATE_ORI_ABS, this value specifies
  139. * the absolute number of the row in the result set that shall be fetched.
  140. *
  141. * For a PDOStatement object representing a scrollable cursor for
  142. * which the $cursorOrientation parameter is set to Query::HYDRATE_ORI_REL, this value
  143. * specifies the row to fetch relative to the cursor position before
  144. * PDOStatement->fetch() was called.
  145. *
  146. * @return mixed
  147. */
  148. function fetch($fetchStyle = PDO::FETCH_BOTH);
  149. /**
  150. * Returns an array containing all of the result set rows
  151. *
  152. * @param integer $fetchStyle Controls how the next row will be returned to the caller.
  153. * This value must be one of the Query::HYDRATE_* constants,
  154. * defaulting to Query::HYDRATE_BOTH
  155. *
  156. * @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
  157. * Query::HYDRATE_COLUMN. Defaults to 0.
  158. *
  159. * @return array
  160. */
  161. function fetchAll($fetchStyle = PDO::FETCH_BOTH);
  162. /**
  163. * fetchColumn
  164. * Returns a single column from the next row of a
  165. * result set or FALSE if there are no more rows.
  166. *
  167. * @param integer $columnIndex 0-indexed number of the column you wish to retrieve from the row. If no
  168. * value is supplied, PDOStatement->fetchColumn()
  169. * fetches the first column.
  170. *
  171. * @return string returns a single column in the next row of a result set.
  172. */
  173. function fetchColumn($columnIndex = 0);
  174. /**
  175. * rowCount
  176. * rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
  177. * executed by the corresponding object.
  178. *
  179. * If the last SQL statement executed by the associated Statement object was a SELECT statement,
  180. * some databases may return the number of rows returned by that statement. However,
  181. * this behaviour is not guaranteed for all databases and should not be
  182. * relied on for portable applications.
  183. *
  184. * @return integer Returns the number of rows.
  185. */
  186. function rowCount();
  187. }