/**
  * Generic execute() function has to check to see whether SQL is an update or select query.
  * 
  * If you already know whether it's a SELECT or an update (manipulating) SQL, then use
  * the appropriate method, as this one will incurr overhead to check the SQL.
  * 
  * @param int $fetchmode Fetchmode (only applies to queries).
  * @return boolean True if it is a result set, false if not or if no more results (this is identical to JDBC return val).
  * @throws SQLException
  * @todo -cStatementCommon Update execute() to not use isSelect() method, but rather to determine type based on returned results.
  */
 public function execute($sql, $fetchmode = null)
 {
     if (!$this->isSelect($sql)) {
         $this->updateCount = $this->executeUpdate($sql);
         return false;
     } else {
         $this->resultSet = $this->executeQuery($sql, $fetchmode);
         if ($this->resultSet->getRecordCount() === 0) {
             return false;
         }
         return true;
     }
 }
示例#2
0
 /**
  * Returns an ActiveRecord object
  *
  * @throws RecordNotFoundException 
  * @return ActiveRecord
  */
 protected static function fetch_one(ResultSet $rs, ReflectionClass $class)
 {
     if ($rs->getRecordCount() != 1) {
         $rs->close();
         throw new RecordNotFoundException('Couldn\'t find a `' . $class->getName() . '` to match your query.');
     }
     $rs->next();
     $ar = $class->newInstance($rs->getRow());
     $rs->close();
     return $ar;
 }