Hoa central
Statement.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Database\Layer\Pdo;
38 
39 use Hoa\Database;
40 
50 {
56  protected $_statement = null;
57 
58 
59 
66  public function __construct(\PDOStatement $statement)
67  {
68  $this->setStatement($statement);
69 
70  return;
71  }
72 
79  protected function setStatement(\PDOStatement $statement)
80  {
81  $old = $this->_statement;
82  $this->_statement = $statement;
83 
84  return $old;
85  }
86 
92  protected function getStatement()
93  {
94  return $this->_statement;
95  }
96 
105  public function execute(Array $bindParameters = null)
106  {
107  if (false === $this->getStatement()->execute($bindParameters)) {
108  throw new Database\Exception(
109  '%3$s (%1$s/%2$d)',
110  0,
111  $this->errorInfo()
112  );
113  }
114 
115  return $this;
116  }
117 
128  public function bindParameter(
129  $parameter,
130  &$value,
131  $type = null,
132  $length = null
133  ) {
134  if (null === $type) {
135  return $this->getStatement()->bindParam($parameter, $value);
136  }
137 
138  if (null === $length) {
139  return $this->getStatement()->bindParam($parameter, $value, $type);
140  }
141 
142  return $this->getStatement()->bindParam($parameter, $value, $type, $length);
143  }
144 
151  public function fetchAll()
152  {
153  return $this->getStatement()->fetchAll(\PDO::FETCH_ASSOC);
154  }
155 
164  protected function fetch($orientation = \PDO::FETCH_ORI_NEXT)
165  {
166  return $this->getStatement()->fetch(
167  \PDO::FETCH_ASSOC,
168  $orientation
169  );
170  }
171 
178  public function fetchFirst()
179  {
180  return $this->fetch(\PDO::FETCH_ORI_FIRST);
181  }
182 
189  public function fetchLast()
190  {
191  return $this->fetch(\PDO::FETCH_ORI_LAST);
192  }
193 
200  public function fetchNext()
201  {
202  return $this->fetch(\PDO::FETCH_ORI_NEXT);
203  }
204 
211  public function fetchPrior()
212  {
213  return $this->fetch(\PDO::FETCH_ORI_PRIOR);
214  }
215 
224  public function fetchColumn($column = 0)
225  {
226  return $this->getStatement()->fetchColumn($column);
227  }
228 
235  public function closeCursor()
236  {
237  return $this->getStatement()->closeCursor();
238  }
239 
247  public function errorCode()
248  {
249  return $this->getStatement()->errorCode();
250  }
251 
259  public function errorInfo()
260  {
261  return $this->getStatement()->errorInfo();
262  }
263 }
execute(Array $bindParameters=null)
Definition: Statement.php:105
fetch($orientation=\PDO::FETCH_ORI_NEXT)
Definition: Statement.php:164
bindParameter($parameter, &$value, $type=null, $length=null)
Definition: Statement.php:128
setStatement(\PDOStatement $statement)
Definition: Statement.php:79
__construct(\PDOStatement $statement)
Definition: Statement.php:66