00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00029 abstract class StatementCommon {
00030
00035 protected $conn;
00036
00041 protected $resultSet;
00042
00047 protected $updateCount;
00048
00053 protected $warnings = array();
00054
00059 protected $resultClass;
00060
00065 protected $stmt;
00066
00071 protected $limit = 0;
00072
00078 protected $offset = 0;
00079
00085 function __construct(Connection $conn)
00086 {
00087 $this->conn = $conn;
00088 }
00089
00097 public function setLimit($v)
00098 {
00099 $this->limit = (int) $v;
00100 }
00101
00106 public function getLimit()
00107 {
00108 return $this->limit;
00109 }
00110
00119 public function setOffset($v)
00120 {
00121 $this->offset = (int) $v;
00122 }
00123
00129 public function getOffset()
00130 {
00131 return $this->offset;
00132 }
00133
00141 public function close()
00142 {
00143
00144 }
00145
00157 public function execute($sql, $fetchmode = null)
00158 {
00159
00160 if (!$this->isSelect($sql)) {
00161 $this->updateCount = $this->executeUpdate($sql);
00162 return false;
00163 } else {
00164 $this->resultSet = $this->executeQuery($sql, $fetchmode);
00165 if ($this->resultSet->getRecordCount() === 0) {
00166 return false;
00167 }
00168 return true;
00169 }
00170 }
00171
00179 public function getResultSet()
00180 {
00181 return $this->resultSet;
00182 }
00183
00189 public function getUpdateCount()
00190 {
00191 return $this->updateCount;
00192 }
00193
00219 protected function isSelect($sql)
00220 {
00221
00222
00223 $sql = trim($sql);
00224 return (stripos($sql, 'select') === 0 && stripos($sql, 'select into ') !== 0);
00225 }
00226
00236 public function executeQuery($sql, $fetchmode = null)
00237 {
00238 $this->updateCount = null;
00239 if ($this->limit > 0 || $this->offset > 0) {
00240 $this->conn->applyLimit($sql, $this->offset, $this->limit);
00241 }
00242 $this->resultSet = $this->conn->executeQuery($sql, $fetchmode);
00243 return $this->resultSet;
00244 }
00245
00253 public function executeUpdate($sql)
00254 {
00255 if ($this->resultSet) $this->resultSet->close();
00256 $this->resultSet = null;
00257 $this->updateCount = $this->conn->executeUpdate($sql);
00258 return $this->updateCount;
00259 }
00260
00274 public function getMoreResults()
00275 {
00276 if ($this->resultSet) $this->resultSet->close();
00277 $this->resultSet = null;
00278 return false;
00279 }
00280
00285 public function getConnection()
00286 {
00287 return $this->conn;
00288 }
00289 }