00001 <?php 00026 require_once 'Zend/Db/Statement.php'; 00027 00040 class Zend_Db_Statement_Pdo extends Zend_Db_Statement implements IteratorAggregate 00041 { 00042 00046 protected $_fetchMode = PDO::FETCH_ASSOC; 00047 00055 protected function _prepare($sql) 00056 { 00057 try { 00058 $this->_stmt = $this->_adapter->getConnection()->prepare($sql); 00059 } catch (PDOException $e) { 00060 require_once 'Zend/Db/Statement/Exception.php'; 00061 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00062 } 00063 } 00064 00075 public function bindColumn($column, &$param, $type = null) 00076 { 00077 try { 00078 if ($type === null) { 00079 return $this->_stmt->bindColumn($column, $param); 00080 } else { 00081 return $this->_stmt->bindColumn($column, $param, $type); 00082 } 00083 } catch (PDOException $e) { 00084 require_once 'Zend/Db/Statement/Exception.php'; 00085 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00086 } 00087 } 00088 00100 protected function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null) 00101 { 00102 try { 00103 if ($type === null) { 00104 if (is_bool($variable)) { 00105 $type = PDO::PARAM_BOOL; 00106 } elseif ($variable === null) { 00107 $type = PDO::PARAM_NULL; 00108 } elseif (is_integer($variable)) { 00109 $type = PDO::PARAM_INT; 00110 } else { 00111 $type = PDO::PARAM_STR; 00112 } 00113 } 00114 return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options); 00115 } catch (PDOException $e) { 00116 require_once 'Zend/Db/Statement/Exception.php'; 00117 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00118 } 00119 } 00120 00130 public function bindValue($parameter, $value, $type = null) 00131 { 00132 if (is_string($parameter) && $parameter[0] != ':') { 00133 $parameter = ":$parameter"; 00134 } 00135 00136 $this->_bindParam[$parameter] = $value; 00137 00138 try { 00139 if ($type === null) { 00140 return $this->_stmt->bindValue($parameter, $value); 00141 } else { 00142 return $this->_stmt->bindValue($parameter, $value, $type); 00143 } 00144 } catch (PDOException $e) { 00145 require_once 'Zend/Db/Statement/Exception.php'; 00146 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00147 } 00148 } 00149 00156 public function closeCursor() 00157 { 00158 try { 00159 return $this->_stmt->closeCursor(); 00160 } catch (PDOException $e) { 00161 require_once 'Zend/Db/Statement/Exception.php'; 00162 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00163 } 00164 } 00165 00173 public function columnCount() 00174 { 00175 try { 00176 return $this->_stmt->columnCount(); 00177 } catch (PDOException $e) { 00178 require_once 'Zend/Db/Statement/Exception.php'; 00179 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00180 } 00181 } 00182 00190 public function errorCode() 00191 { 00192 try { 00193 return $this->_stmt->errorCode(); 00194 } catch (PDOException $e) { 00195 require_once 'Zend/Db/Statement/Exception.php'; 00196 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00197 } 00198 } 00199 00207 public function errorInfo() 00208 { 00209 try { 00210 return $this->_stmt->errorInfo(); 00211 } catch (PDOException $e) { 00212 require_once 'Zend/Db/Statement/Exception.php'; 00213 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00214 } 00215 } 00216 00224 public function _execute(array $params = null) 00225 { 00226 try { 00227 if ($params !== null) { 00228 return $this->_stmt->execute($params); 00229 } else { 00230 return $this->_stmt->execute(); 00231 } 00232 } catch (PDOException $e) { 00233 require_once 'Zend/Db/Statement/Exception.php'; 00234 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00235 } 00236 } 00237 00247 public function fetch($style = null, $cursor = null, $offset = null) 00248 { 00249 if ($style === null) { 00250 $style = $this->_fetchMode; 00251 } 00252 try { 00253 return $this->_stmt->fetch($style, $cursor, $offset); 00254 } catch (PDOException $e) { 00255 require_once 'Zend/Db/Statement/Exception.php'; 00256 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00257 } 00258 } 00259 00265 public function getIterator() 00266 { 00267 return new IteratorIterator($this->_stmt); 00268 } 00269 00278 public function fetchAll($style = null, $col = null) 00279 { 00280 if ($style === null) { 00281 $style = $this->_fetchMode; 00282 } 00283 try { 00284 if ($style == PDO::FETCH_COLUMN) { 00285 if ($col === null) { 00286 $col = 0; 00287 } 00288 return $this->_stmt->fetchAll($style, $col); 00289 } else { 00290 return $this->_stmt->fetchAll($style); 00291 } 00292 } catch (PDOException $e) { 00293 require_once 'Zend/Db/Statement/Exception.php'; 00294 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00295 } 00296 } 00297 00305 public function fetchColumn($col = 0) 00306 { 00307 try { 00308 return $this->_stmt->fetchColumn($col); 00309 } catch (PDOException $e) { 00310 require_once 'Zend/Db/Statement/Exception.php'; 00311 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00312 } 00313 } 00314 00323 public function fetchObject($class = 'stdClass', array $config = array()) 00324 { 00325 try { 00326 return $this->_stmt->fetchObject($class, $config); 00327 } catch (PDOException $e) { 00328 require_once 'Zend/Db/Statement/Exception.php'; 00329 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00330 } 00331 } 00332 00340 public function getAttribute($key) 00341 { 00342 try { 00343 return $this->_stmt->getAttribute($key); 00344 } catch (PDOException $e) { 00345 require_once 'Zend/Db/Statement/Exception.php'; 00346 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00347 } 00348 } 00349 00357 public function getColumnMeta($column) 00358 { 00359 try { 00360 return $this->_stmt->getColumnMeta($column); 00361 } catch (PDOException $e) { 00362 require_once 'Zend/Db/Statement/Exception.php'; 00363 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00364 } 00365 } 00366 00375 public function nextRowset() 00376 { 00377 try { 00378 return $this->_stmt->nextRowset(); 00379 } catch (PDOException $e) { 00380 require_once 'Zend/Db/Statement/Exception.php'; 00381 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00382 } 00383 } 00384 00393 public function rowCount() 00394 { 00395 try { 00396 return $this->_stmt->rowCount(); 00397 } catch (PDOException $e) { 00398 require_once 'Zend/Db/Statement/Exception.php'; 00399 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00400 } 00401 } 00402 00411 public function setAttribute($key, $val) 00412 { 00413 try { 00414 return $this->_stmt->setAttribute($key, $val); 00415 } catch (PDOException $e) { 00416 require_once 'Zend/Db/Statement/Exception.php'; 00417 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00418 } 00419 } 00420 00428 public function setFetchMode($mode) 00429 { 00430 $this->_fetchMode = $mode; 00431 try { 00432 return $this->_stmt->setFetchMode($mode); 00433 } catch (PDOException $e) { 00434 require_once 'Zend/Db/Statement/Exception.php'; 00435 throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); 00436 } 00437 } 00438 00439 }