TransactionEnd() public method

Ends a transaction and commits the queries
public TransactionEnd ( ) : boolean
return boolean Returns TRUE on success or FALSE on error
示例#1
0
文件: example.php 项目: kimai/kimai
// you fill in the values when you create the obect, this is not needed.)
if (!$db->Open("test", "localhost", "root", "password")) {
    $db->Kill();
}
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 -------------------------------------
if (!$db->Query($sql)) {
    $success = false;
}
$sql = "INSERT INTO test (Color, Age) VALUES ('Yellow', '1')";
if (!$db->Query($sql)) {
    $success = false;
}
// Notice that you can even view what the new IDs are going to be before
// the records are commited. Transaction processing allows you to
// actually see what the final results will look like in the database.
echo "The new ID for the last inserted record is " . $db->GetLastInsertID();
echo "<br />\r";
// If there were no errors...
if ($success) {
    // Commit the transaction and save these records to the database
    if (!$db->TransactionEnd()) {
        $db->Kill();
    }
} else {
    // Otherwise, there were errors...
    // Rollback our transaction
    if (!$db->TransactionRollback()) {
        $db->Kill();
    }
}
// Transaction processing works with INSERT, UPDATES, and DELETE queries.
// They are terrific to use in TRY/CATCH blocks for error handling.
// Turn on exception handling
$db->ThrowExceptions = true;
// Here's our try/catch block
try {
示例#3
0
文件: Mysql.php 项目: kimai/kimai
 /**
  * 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;
 }
示例#4
0
//brand
$sql = "SELECT * from import_hkstock";
$gethk = $db->QueryArray($sql);
$new_id = $db->InsertRow("webstock", $insert);
if (!$new_id) {
    //print_r ($insert);
    die('Unable to write record to DB.');
}
unset($insert);
echo '</table>';
//echo('<input type="submit" name="submit" value="submit" />');
echo '</form>';
echo '<br><h4>Finished, you may close this page, </h4></body>';
// If there were no errors...
// Commit the transaction and save these records to the database
if ($db->TransactionEnd()) {
    $db->Kill();
    $db->Release();
    print "<br><h1>Succesful database write!</h1><br>";
    shell_exec('/usr/local/bin/php /home/worldog9/www/hkstock/drucon.php');
} else {
    // Otherwise, there were errors...
    // Rollback our transaction
    $db->TransactionRollback();
    $db->Kill();
    $db->Release();
    print "<br><h1>FAILURE in database write!</h1><br>";
}
class timerClass
{
    var $startTime;