MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
DB2Statement.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
23
25{
26 private $_stmt = null;
27
28 private $_bindParam = array();
29
34 static private $_typeMap = array(
35 \PDO::PARAM_INT => DB2_LONG,
36 \PDO::PARAM_STR => DB2_CHAR,
37 );
38
39 public function __construct($stmt)
40 {
41 $this->_stmt = $stmt;
42 }
43
57 function bindValue($param, $value, $type = null)
58 {
59 return $this->bindParam($param, $value, $type);
60 }
61
84 function bindParam($column, &$variable, $type = null)
85 {
86 $this->_bindParam[$column] =& $variable;
87
88 if ($type && isset(self::$_typeMap[$type])) {
89 $type = self::$_typeMap[$type];
90 } else {
91 $type = DB2_CHAR;
92 }
93
94 if (!db2_bind_param($this->_stmt, $column, "variable", DB2_PARAM_IN, $type)) {
95 throw new DB2Exception(db2_stmt_errormsg());
96 }
97 return true;
98 }
99
105 function closeCursor()
106 {
107 if (!$this->_stmt) {
108 return false;
109 }
110
111 $this->_bindParam = array();
112 db2_free_result($this->_stmt);
113 $ret = db2_free_stmt($this->_stmt);
114 $this->_stmt = false;
115 return $ret;
116 }
117
126 function columnCount()
127 {
128 if (!$this->_stmt) {
129 return false;
130 }
131 return db2_num_fields($this->_stmt);
132 }
133
141 function errorCode()
142 {
143 return db2_stmt_error();
144 }
145
153 function errorInfo()
154 {
155 return array(
156 0 => db2_stmt_errormsg(),
157 1 => db2_stmt_error(),
158 );
159 }
160
175 function execute($params = null)
176 {
177 if (!$this->_stmt) {
178 return false;
179 }
180
181 /*$retval = true;
182 if ($params !== null) {
183 $retval = @db2_execute($this->_stmt, $params);
184 } else {
185 $retval = @db2_execute($this->_stmt);
186 }*/
187 if ($params === null) {
188 ksort($this->_bindParam);
189 $params = array_values($this->_bindParam);
190 }
191 $retval = @db2_execute($this->_stmt, $params);
192
193 if ($retval === false) {
194 throw new DB2Exception(db2_stmt_errormsg());
195 }
196 return $retval;
197 }
198
226 function fetch($fetchStyle = \PDO::FETCH_BOTH)
227 {
228 switch ($fetchStyle) {
229 case \PDO::FETCH_BOTH:
230 return db2_fetch_both($this->_stmt);
231 case \PDO::FETCH_ASSOC:
232 return db2_fetch_assoc($this->_stmt);
233 case \PDO::FETCH_NUM:
234 return db2_fetch_array($this->_stmt);
235 default:
236 throw new DB2Exception("Given Fetch-Style " . $fetchStyle . " is not supported.");
237 }
238 }
239
252 function fetchAll($fetchStyle = \PDO::FETCH_BOTH)
253 {
254 $rows = array();
255 while ($row = $this->fetch($fetchStyle)) {
256 $rows[] = $row;
257 }
258 return $rows;
259 }
260
272 function fetchColumn($columnIndex = 0)
273 {
274 $row = $this->fetch(\PDO::FETCH_NUM);
275 if ($row && isset($row[$columnIndex])) {
276 return $row[$columnIndex];
277 }
278 return false;
279 }
280
293 function rowCount()
294 {
295 return (@db2_num_rows($this->_stmt))?:0;
296 }
297}
bindParam($column, &$variable, $type=null)
bindValue($param, $value, $type=null)
fetch($fetchStyle=\PDO::FETCH_BOTH)
fetchAll($fetchStyle=\PDO::FETCH_BOTH)