MySQL::TransactionRollback PHP Méthode

TransactionRollback() public méthode

Rolls the transaction back
public TransactionRollback ( ) : boolean
Résultat boolean Returns TRUE on success or FALSE on failure
    public function TransactionRollback()
    {
        $this->ResetError();
        if (!$this->IsConnected()) {
            $this->SetError("No connection");
            return false;
        } else {
            if (!mysqli_query($this->mysql_link, "ROLLBACK")) {
                $this->SetError("Could not rollback transaction");
                return false;
            } else {
                $this->in_transaction = false;
                return true;
            }
        }
    }

Usage Example

Exemple #1
0
 /**
  * edit time sheet entry
  *
  * @param integer $id ID of record
  * @param array $data array with new record data
  * @author th
  * @return bool
  */
 public function timeEntry_edit($id, array $data)
 {
     $data = $this->clean_data($data);
     $original_array = $this->timeSheet_get_data($id);
     $new_array = array();
     $budgetChange = 0;
     $approvedChange = 0;
     foreach ($original_array as $key => $value) {
         if (isset($data[$key]) == true) {
             // budget is added to total budget for activity. So if we change the budget, we need
             // to first subtract the previous entry before adding the new one
             //          	if($key == 'budget') {
             //          		$budgetChange = - $value;
             //          	} else if($key == 'approved') {
             //          		$approvedChange = - $value;
             //          	}
             $new_array[$key] = $data[$key];
         } else {
             $new_array[$key] = $original_array[$key];
         }
     }
     $values['description'] = MySQL::SQLValue($new_array['description']);
     $values['comment'] = MySQL::SQLValue($new_array['comment']);
     $values['location'] = MySQL::SQLValue($new_array['location']);
     if ($new_array['trackingNumber'] == '') {
         $values['trackingNumber'] = 'NULL';
     } else {
         $values['trackingNumber'] = MySQL::SQLValue($new_array['trackingNumber']);
     }
     $values['userID'] = MySQL::SQLValue($new_array['userID'], MySQL::SQLVALUE_NUMBER);
     $values['projectID'] = MySQL::SQLValue($new_array['projectID'], MySQL::SQLVALUE_NUMBER);
     $values['activityID'] = MySQL::SQLValue($new_array['activityID'], MySQL::SQLVALUE_NUMBER);
     $values['commentType'] = MySQL::SQLValue($new_array['commentType'], MySQL::SQLVALUE_NUMBER);
     $values['start'] = MySQL::SQLValue($new_array['start'], MySQL::SQLVALUE_NUMBER);
     $values['end'] = MySQL::SQLValue($new_array['end'], MySQL::SQLVALUE_NUMBER);
     $values['duration'] = MySQL::SQLValue($new_array['duration'], MySQL::SQLVALUE_NUMBER);
     $values['rate'] = MySQL::SQLValue($new_array['rate'], MySQL::SQLVALUE_NUMBER);
     $values['fixedRate'] = MySQL::SQLValue($new_array['fixedRate'], MySQL::SQLVALUE_NUMBER);
     $values['cleared'] = MySQL::SQLValue($new_array['cleared'] ? 1 : 0, MySQL::SQLVALUE_NUMBER);
     $values['budget'] = MySQL::SQLValue($new_array['budget'], MySQL::SQLVALUE_NUMBER);
     $values['approved'] = MySQL::SQLValue($new_array['approved'], MySQL::SQLVALUE_NUMBER);
     $values['statusID'] = MySQL::SQLValue($new_array['statusID'], MySQL::SQLVALUE_NUMBER);
     $values['billable'] = MySQL::SQLValue($new_array['billable'], MySQL::SQLVALUE_NUMBER);
     $filter['timeEntryID'] = MySQL::SQLValue($id, MySQL::SQLVALUE_NUMBER);
     $table = $this->kga['server_prefix'] . "timeSheet";
     if (!$this->conn->TransactionBegin()) {
         $this->logLastError('timeEntry_edit');
         return false;
     }
     $query = MySQL::BuildSQLUpdate($table, $values, $filter);
     $success = true;
     if (!$this->conn->Query($query)) {
         $success = false;
     }
     if ($success) {
         if (!$this->conn->TransactionEnd()) {
             $this->logLastError('timeEntry_edit');
             return false;
         }
     } else {
         // $budgetChange += $values['budget'];
         // $approvedChange += $values['approved'];
         // $this->update_evt_budget($values['projectID'], $values['activityID'], $budgetChange);
         // $this->update_evt_approved($values['projectID'], $values['activityID'], $budgetChange);
         $this->logLastError('timeEntry_edit');
         if (!$this->conn->TransactionRollback()) {
             $this->logLastError('timeEntry_edit');
             return false;
         }
     }
     return $success;
 }
All Usage Examples Of MySQL::TransactionRollback