Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Db2.php
Go to the documentation of this file.
1 <?php
26 #require_once 'Zend/Db/Statement.php';
27 
37 {
38 
42  protected $_keys;
43 
47  protected $_values;
48 
56  public function _prepare($sql)
57  {
58  $connection = $this->_adapter->getConnection();
59 
60  // db2_prepare on i5 emits errors, these need to be
61  // suppressed so that proper exceptions can be thrown
62  $this->_stmt = @db2_prepare($connection, $sql);
63 
64  if (!$this->_stmt) {
68  #require_once 'Zend/Db/Statement/Db2/Exception.php';
70  db2_stmt_errormsg(),
71  db2_stmt_error()
72  );
73  }
74  }
75 
87  public function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
88  {
89  if ($type === null) {
90  $type = DB2_PARAM_IN;
91  }
92 
93  if (isset($options['data-type'])) {
94  $datatype = $options['data-type'];
95  } else {
96  $datatype = DB2_CHAR;
97  }
98 
99  if (!db2_bind_param($this->_stmt, $parameter, "variable", $type, $datatype)) {
103  #require_once 'Zend/Db/Statement/Db2/Exception.php';
105  db2_stmt_errormsg(),
106  db2_stmt_error()
107  );
108  }
109 
110  return true;
111  }
112 
118  public function closeCursor()
119  {
120  if (!$this->_stmt) {
121  return false;
122  }
123  db2_free_stmt($this->_stmt);
124  $this->_stmt = false;
125  return true;
126  }
127 
128 
135  public function columnCount()
136  {
137  if (!$this->_stmt) {
138  return false;
139  }
140  return db2_num_fields($this->_stmt);
141  }
142 
149  public function errorCode()
150  {
151  if (!$this->_stmt) {
152  return false;
153  }
154 
155  $error = db2_stmt_error();
156  if ($error === '') {
157  return false;
158  }
159 
160  return $error;
161  }
162 
169  public function errorInfo()
170  {
171  $error = $this->errorCode();
172  if ($error === false){
173  return false;
174  }
175 
176  /*
177  * Return three-valued array like PDO. But DB2 does not distinguish
178  * between SQLCODE and native RDBMS error code, so repeat the SQLCODE.
179  */
180  return array(
181  $error,
182  $error,
183  db2_stmt_errormsg()
184  );
185  }
186 
194  public function _execute(array $params = null)
195  {
196  if (!$this->_stmt) {
197  return false;
198  }
199 
200  $retval = true;
201  if ($params !== null) {
202  $retval = @db2_execute($this->_stmt, $params);
203  } else {
204  $retval = @db2_execute($this->_stmt);
205  }
206 
207  if ($retval === false) {
211  #require_once 'Zend/Db/Statement/Db2/Exception.php';
213  db2_stmt_errormsg(),
214  db2_stmt_error());
215  }
216 
217  $this->_keys = array();
218  if ($field_num = $this->columnCount()) {
219  for ($i = 0; $i < $field_num; $i++) {
220  $name = db2_field_name($this->_stmt, $i);
221  $this->_keys[] = $name;
222  }
223  }
224 
225  $this->_values = array();
226  if ($this->_keys) {
227  $this->_values = array_fill(0, count($this->_keys), null);
228  }
229 
230  return $retval;
231  }
232 
242  public function fetch($style = null, $cursor = null, $offset = null)
243  {
244  if (!$this->_stmt) {
245  return false;
246  }
247 
248  if ($style === null) {
249  $style = $this->_fetchMode;
250  }
251 
252  switch ($style) {
253  case Zend_Db::FETCH_NUM :
254  $row = db2_fetch_array($this->_stmt);
255  break;
256  case Zend_Db::FETCH_ASSOC :
257  $row = db2_fetch_assoc($this->_stmt);
258  break;
259  case Zend_Db::FETCH_BOTH :
260  $row = db2_fetch_both($this->_stmt);
261  break;
262  case Zend_Db::FETCH_OBJ :
263  $row = db2_fetch_object($this->_stmt);
264  break;
266  $row = db2_fetch_both($this->_stmt);
267  if ($row !== false) {
268  return $this->_fetchBound($row);
269  }
270  break;
271  default:
275  #require_once 'Zend/Db/Statement/Db2/Exception.php';
276  throw new Zend_Db_Statement_Db2_Exception("Invalid fetch mode '$style' specified");
277  break;
278  }
279 
280  return $row;
281  }
282 
290  public function fetchObject($class = 'stdClass', array $config = array())
291  {
292  $obj = $this->fetch(Zend_Db::FETCH_OBJ);
293  return $obj;
294  }
295 
304  public function nextRowset()
305  {
309  #require_once 'Zend/Db/Statement/Db2/Exception.php';
310  throw new Zend_Db_Statement_Db2_Exception(__FUNCTION__ . '() is not implemented');
311  }
312 
320  public function rowCount()
321  {
322  if (!$this->_stmt) {
323  return false;
324  }
325 
326  $num = @db2_num_rows($this->_stmt);
327 
328  if ($num === false) {
329  return 0;
330  }
331 
332  return $num;
333  }
334 
346  public function fetchAll($style = null, $col = null)
347  {
348  $data = parent::fetchAll($style, $col);
349  $results = array();
350  $remove = $this->_adapter->foldCase('ZEND_DB_ROWNUM');
351 
352  foreach ($data as $row) {
353  if (is_array($row) && array_key_exists($remove, $row)) {
354  unset($row[$remove]);
355  }
356  $results[] = $row;
357  }
358  return $results;
359  }
360 }
fetchObject($class='stdClass', array $config=array())
Definition: Db2.php:290
$results
Definition: popup.phtml:13
$config
Definition: fraud_order.php:17
const FETCH_BOUND
Definition: Db.php:144
const FETCH_ASSOC
Definition: Db.php:142
$variable
Definition: variable.php:7
$type
Definition: item.phtml:13
const FETCH_BOTH
Definition: Db.php:143
$_option $_optionId $class
Definition: date.phtml:13
const FETCH_NUM
Definition: Db.php:153
_execute(array $params=null)
Definition: Db2.php:194
_bindParam($parameter, &$variable, $type=null, $length=null, $options=null)
Definition: Db2.php:87
const FETCH_OBJ
Definition: Db.php:154
fetch($style=null, $cursor=null, $offset=null)
Definition: Db2.php:242
$connection
Definition: bulk.php:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
fetchAll($style=null, $col=null)
Definition: Db2.php:346
$i
Definition: gallery.phtml:31
if(!isset($_GET['name'])) $name
Definition: log.php:14