MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
Statement.php
Ir para a documentação deste ficheiro.
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
22namespace Doctrine\DBAL;
23
24use PDO,
26 Doctrine\DBAL\Driver\Statement as DriverStatement;
27
35class Statement implements DriverStatement
36{
40 private $_sql;
44 private $_params = array();
48 private $_stmt;
52 private $_platform;
56 private $_conn;
57
64 public function __construct($sql, Connection $conn)
65 {
66 $this->_sql = $sql;
67 $this->_stmt = $conn->getWrappedConnection()->prepare($sql);
68 $this->_conn = $conn;
69 $this->_platform = $conn->getDatabasePlatform();
70 }
71
85 public function bindValue($name, $value, $type = null)
86 {
87 $this->_params[$name] = $value;
88 if ($type !== null) {
89 if (is_string($type)) {
90 $type = Type::getType($type);
91 }
92 if ($type instanceof Type) {
93 $value = $type->convertToDatabaseValue($value, $this->_platform);
94 $bindingType = $type->getBindingType();
95 } else {
96 $bindingType = $type; // PDO::PARAM_* constants
97 }
98 return $this->_stmt->bindValue($name, $value, $bindingType);
99 } else {
100 return $this->_stmt->bindValue($name, $value);
101 }
102 }
103
114 public function bindParam($name, &$var, $type = PDO::PARAM_STR)
115 {
116 return $this->_stmt->bindParam($name, $var, $type);
117 }
118
124 public function execute($params = null)
125 {
126 $hasLogger = $this->_conn->getConfiguration()->getSQLLogger();
127 if ($hasLogger) {
128 $this->_conn->getConfiguration()->getSQLLogger()->startQuery($this->_sql, $this->_params);
129 }
130
131 $stmt = $this->_stmt->execute($params);
132
133 if ($hasLogger) {
134 $this->_conn->getConfiguration()->getSQLLogger()->stopQuery();
135 }
136 $this->_params = array();
137 return $stmt;
138 }
139
145 public function closeCursor()
146 {
147 return $this->_stmt->closeCursor();
148 }
149
155 public function columnCount()
156 {
157 return $this->_stmt->columnCount();
158 }
159
165 public function errorCode()
166 {
167 return $this->_stmt->errorCode();
168 }
169
175 public function errorInfo()
176 {
177 return $this->_stmt->errorInfo();
178 }
179
187 public function fetch($fetchStyle = PDO::FETCH_BOTH)
188 {
189 return $this->_stmt->fetch($fetchStyle);
190 }
191
199 public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0)
200 {
201 if ($columnIndex != 0) {
202 return $this->_stmt->fetchAll($fetchStyle, $columnIndex);
203 }
204 return $this->_stmt->fetchAll($fetchStyle);
205 }
206
213 public function fetchColumn($columnIndex = 0)
214 {
215 return $this->_stmt->fetchColumn($columnIndex);
216 }
217
223 public function rowCount()
224 {
225 return $this->_stmt->rowCount();
226 }
227
233 public function getWrappedStatement()
234 {
235 return $this->_stmt;
236 }
237}
fetchAll($fetchStyle=PDO::FETCH_BOTH, $columnIndex=0)
Definição Statement.php:199
bindParam($name, &$var, $type=PDO::PARAM_STR)
Definição Statement.php:114
__construct($sql, Connection $conn)
Definição Statement.php:64
bindValue($name, $value, $type=null)
Definição Statement.php:85
execute($params=null)
Definição Statement.php:124
fetchColumn($columnIndex=0)
Definição Statement.php:213
fetch($fetchStyle=PDO::FETCH_BOTH)
Definição Statement.php:187