Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Pdo.php
Go to the documentation of this file.
1 <?php
26 #require_once 'Zend/Db/Statement.php';
27 
40 class Zend_Db_Statement_Pdo extends Zend_Db_Statement implements IteratorAggregate
41 {
42 
46  protected $_fetchMode = PDO::FETCH_ASSOC;
47 
55  protected function _prepare($sql)
56  {
57  try {
58  $this->_stmt = $this->_adapter->getConnection()->prepare($sql);
59  } catch (PDOException $e) {
60  #require_once 'Zend/Db/Statement/Exception.php';
61  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
62  }
63  }
64 
75  public function bindColumn($column, &$param, $type = null)
76  {
77  try {
78  if ($type === null) {
79  return $this->_stmt->bindColumn($column, $param);
80  } else {
81  return $this->_stmt->bindColumn($column, $param, $type);
82  }
83  } catch (PDOException $e) {
84  #require_once 'Zend/Db/Statement/Exception.php';
85  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
86  }
87  }
88 
100  protected function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
101  {
102  try {
103  if ($type === null) {
104  if (is_bool($variable)) {
105  $type = PDO::PARAM_BOOL;
106  } elseif ($variable === null) {
107  $type = PDO::PARAM_NULL;
108  } elseif (is_integer($variable)) {
109  $type = PDO::PARAM_INT;
110  } else {
111  $type = PDO::PARAM_STR;
112  }
113  }
114  return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options);
115  } catch (PDOException $e) {
116  #require_once 'Zend/Db/Statement/Exception.php';
117  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
118  }
119  }
120 
130  public function bindValue($parameter, $value, $type = null)
131  {
132  if (is_string($parameter) && $parameter[0] != ':') {
133  $parameter = ":$parameter";
134  }
135 
136  $this->_bindParam[$parameter] = $value;
137 
138  try {
139  if ($type === null) {
140  return $this->_stmt->bindValue($parameter, $value);
141  } else {
142  return $this->_stmt->bindValue($parameter, $value, $type);
143  }
144  } catch (PDOException $e) {
145  #require_once 'Zend/Db/Statement/Exception.php';
146  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
147  }
148  }
149 
156  public function closeCursor()
157  {
158  try {
159  return $this->_stmt->closeCursor();
160  } catch (PDOException $e) {
161  #require_once 'Zend/Db/Statement/Exception.php';
162  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
163  }
164  }
165 
173  public function columnCount()
174  {
175  try {
176  return $this->_stmt->columnCount();
177  } catch (PDOException $e) {
178  #require_once 'Zend/Db/Statement/Exception.php';
179  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
180  }
181  }
182 
190  public function errorCode()
191  {
192  try {
193  return $this->_stmt->errorCode();
194  } catch (PDOException $e) {
195  #require_once 'Zend/Db/Statement/Exception.php';
196  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
197  }
198  }
199 
207  public function errorInfo()
208  {
209  try {
210  return $this->_stmt->errorInfo();
211  } catch (PDOException $e) {
212  #require_once 'Zend/Db/Statement/Exception.php';
213  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
214  }
215  }
216 
224  public function _execute(array $params = null)
225  {
226  try {
227  if ($params !== null) {
228  return $this->_stmt->execute($params);
229  } else {
230  return $this->_stmt->execute();
231  }
232  } catch (PDOException $e) {
233  #require_once 'Zend/Db/Statement/Exception.php';
234  $message = sprintf('%s, query was: %s', $e->getMessage(), $this->_stmt->queryString);
235  throw new Zend_Db_Statement_Exception($message, (int) $e->getCode(), $e);
236  }
237  }
238 
248  public function fetch($style = null, $cursor = null, $offset = null)
249  {
250  if ($style === null) {
251  $style = $this->_fetchMode;
252  }
253  try {
254  return $this->_stmt->fetch($style, $cursor, $offset);
255  } catch (PDOException $e) {
256  #require_once 'Zend/Db/Statement/Exception.php';
257  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
258  }
259  }
260 
266  public function getIterator()
267  {
268  return new IteratorIterator($this->_stmt);
269  }
270 
279  public function fetchAll($style = null, $col = null)
280  {
281  if ($style === null) {
282  $style = $this->_fetchMode;
283  }
284  try {
285  if ($style == PDO::FETCH_COLUMN) {
286  if ($col === null) {
287  $col = 0;
288  }
289  return $this->_stmt->fetchAll($style, $col);
290  } else {
291  return $this->_stmt->fetchAll($style);
292  }
293  } catch (PDOException $e) {
294  #require_once 'Zend/Db/Statement/Exception.php';
295  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
296  }
297  }
298 
306  public function fetchColumn($col = 0)
307  {
308  try {
309  return $this->_stmt->fetchColumn($col);
310  } catch (PDOException $e) {
311  #require_once 'Zend/Db/Statement/Exception.php';
312  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
313  }
314  }
315 
324  public function fetchObject($class = 'stdClass', array $config = array())
325  {
326  try {
327  return $this->_stmt->fetchObject($class, $config);
328  } catch (PDOException $e) {
329  #require_once 'Zend/Db/Statement/Exception.php';
330  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
331  }
332  }
333 
341  public function getAttribute($key)
342  {
343  try {
344  return $this->_stmt->getAttribute($key);
345  } catch (PDOException $e) {
346  #require_once 'Zend/Db/Statement/Exception.php';
347  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
348  }
349  }
350 
358  public function getColumnMeta($column)
359  {
360  try {
361  return $this->_stmt->getColumnMeta($column);
362  } catch (PDOException $e) {
363  #require_once 'Zend/Db/Statement/Exception.php';
364  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
365  }
366  }
367 
376  public function nextRowset()
377  {
378  try {
379  return $this->_stmt->nextRowset();
380  } catch (PDOException $e) {
381  #require_once 'Zend/Db/Statement/Exception.php';
382  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
383  }
384  }
385 
394  public function rowCount()
395  {
396  try {
397  return $this->_stmt->rowCount();
398  } catch (PDOException $e) {
399  #require_once 'Zend/Db/Statement/Exception.php';
400  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
401  }
402  }
403 
412  public function setAttribute($key, $val)
413  {
414  try {
415  return $this->_stmt->setAttribute($key, $val);
416  } catch (PDOException $e) {
417  #require_once 'Zend/Db/Statement/Exception.php';
418  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
419  }
420  }
421 
429  public function setFetchMode($mode)
430  {
431  $this->_fetchMode = $mode;
432  try {
433  return $this->_stmt->setFetchMode($mode);
434  } catch (PDOException $e) {
435  #require_once 'Zend/Db/Statement/Exception.php';
436  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
437  }
438  }
439 
440 }
fetchObject($class='stdClass', array $config=array())
Definition: Pdo.php:324
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
setFetchMode($mode)
Definition: Pdo.php:429
$config
Definition: fraud_order.php:17
setAttribute($key, $val)
Definition: Pdo.php:412
getAttribute($key)
Definition: Pdo.php:341
$message
$variable
Definition: variable.php:7
$type
Definition: item.phtml:13
_bindParam($parameter, &$variable, $type=null, $length=null, $options=null)
Definition: Pdo.php:100
$_option $_optionId $class
Definition: date.phtml:13
$value
Definition: gender.phtml:16
fetchAll($style=null, $col=null)
Definition: Pdo.php:279
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
getColumnMeta($column)
Definition: Pdo.php:358
bindValue($parameter, $value, $type=null)
Definition: Pdo.php:130
_execute(array $params=null)
Definition: Pdo.php:224
fetchColumn($col=0)
Definition: Pdo.php:306
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
fetch($style=null, $cursor=null, $offset=null)
Definition: Pdo.php:248
bindColumn($column, &$param, $type=null)
Definition: Pdo.php:75