示例#1
0
 /**
  * Delete a record from the db.  You probably shouldn't be doing this.
  *
  * Calls preDelete() and postDelete(), if they are defined in the child.
  *
  * TODO: Should this call markUnchanged()?
  */
 public function delete()
 {
     $this->invalidateCache();
     if (!$this->canDelete()) {
         throw new SparkRecordException("can't delete this record - sure you inserted or loaded it from the db?");
     }
     $this->preDelete();
     $dbh = DB::getInstance();
     $tk = static::$_tableKey;
     $tn = static::$_tableName;
     try {
         $sth = $dbh->prepare("DELETE FROM \"{$tn}\" WHERE \"{$tk}\" = :id");
         $sth->execute(['id' => $this->_tableId]);
     } catch (Exception $e) {
         throw new SparkRecordException('Delete failed: ' . $e->getMessage());
     }
     if ($this->_logModifications || count($this->modificationInfo()) > 0) {
         $this->logModifications('DELETE', $this->_record);
     }
     $this->logDelete();
     $this->postDelete();
     return true;
 }
示例#2
0
 protected function getDBH()
 {
     return DB::getInstance();
 }