TransactionRollback() public method

Rolls the transaction back
public TransactionRollback ( ) : boolean
return boolean Returns TRUE on success or FALSE on failure
Beispiel #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;
 }
Beispiel #2
0
}
echo "You are connected to the database<br />\n";
// --- Insert a new record ------------------------------------------
$sql = "INSERT INTO Test (Color, Age) Values ('Red', 7)";
if (!$db->Query($sql)) {
    $db->Kill();
}
echo "Last ID inserted was: " . $db->GetLastInsertID();
// --- Or insert a new record with transaction processing -----------
$sql = "INSERT INTO Test (Color, Age) Values ('Blue', 3)";
$db->TransactionBegin();
if ($db->Query($sql)) {
    $db->TransactionEnd();
    echo "Last ID inserted was: " . $db->GetLastInsertID() . "<br /><br />\n";
} else {
    $db->TransactionRollback();
    echo "<p>Query Failed</p>\n";
}
// --- Query and show the data --------------------------------------
// (Note: $db->Query also returns the result set)
if ($db->Query("SELECT * FROM Test")) {
    echo $db->GetHTML();
} else {
    echo "<p>Query Failed</p>";
}
// --- Getting the record count is easy -----------------------------
echo "\n<p>Record Count: " . $db->RowCount() . "</p>\n";
// --- Loop through the records -------------------------------------
while ($row = $db->Row()) {
    echo $row->Color . " - " . $row->Age . "<br />\n";
}
// you want to remove the other inserts that were done before it.
// Transaction processing allows us to do this. We start a transaction,
// execute some queries, if one fails, all we have to do it rollback. When
// you rollback, any query executed since you began the transaction is
// removed as if it never happened. If they were all successful, then you
// commit and all changes are saved. This can be really useful on larger
// databases that have parent child relationships on the tables.
// Let's start out by creating a new transaction
$db->TransactionBegin();
// Now let's insert some records. We are going to skip checking for any
// query errors just for this part of the example.
$db->Query("INSERT INTO test (Color, Age) VALUES ('Blue', '3')");
$db->Query("INSERT INTO test (Color, Age) VALUES ('Green', '10')");
$db->Query("INSERT INTO test (Color, Age) VALUES ('Yellow', '1')");
// Oops! We don't really want to save these to the database, let's rollback
$db->TransactionRollback();
// Now if you stopped right here and looked in the database, nothing has
// changed... not one thing was saved. It "rolled back" all these inserts.
// NOTE: Transaction processing also works with the InsertRow() and
//       UpdateRow() methods.
// --------------------------------------------------------------------------
// Let's try that again, but this time, we will commit the changes.
// Begin a new transaction, but this time, let's check for errors.
if (!$db->TransactionBegin()) {
    $db->Kill();
}
// We'll create a flag to check for any errors
$success = true;
// Insert some records and if there are any errors, set the flag to false
$sql = "INSERT INTO test (Color, Age) VALUES ('Blue', '3')";
if (!$db->Query($sql)) {