TransactionBegin() public method

Starts a transaction
public TransactionBegin ( ) : boolean
return boolean Returns TRUE on success or FALSE on error
示例#1
0
<?php

// read the matrix specials table and send it to mysql
$cli = "0";
if (isset($argv) && $argv[1] == "cli") {
    $cli = "1";
}
include_once 'mysql.class.php';
include_once 'dbf_class.php';
$db = new MySQL(true) or die('Cannot connect to MySQL server. Please check settings in mysql.class.php');
// Begin a new transaction, but this time, let's check for errors.
if (!$db->TransactionBegin()) {
    $db->Kill();
    die('Cannot start DB transactions...quitting now.');
}
// We'll create a flag to check for any errors
$success = true;
global $hkdata;
//sql building: BE CAREFUL NOT TO USE semicolon inside the sql!!!!
$db->TruncateTable("hkmatrix");
//destroy table data
$sql = "CREATE TABLE IF NOT EXISTS `hkmatrix` (\n  `uid` int(11) NOT NULL AUTO_INCREMENT,\n  `custgroup` varchar(4) NULL,\n  `refnum` varchar(10) NULL,\n  `prodgroup` varchar(254) NULL,\n  `supplier` varchar(254) NULL,\n  `prodcode` varchar(16) NULL,\n  `matrix` varchar(1) NULL,\n  `discount` decimal(10,2) NULL,\n  `contract` decimal(10,2) NULL,\n  `trade` decimal(10,2) NULL,\n  `retail` decimal(10,2) NULL,\n  `date_on` date DEFAULT NULL,\n  `date_off` date DEFAULT NULL,\n\t`break1` decimal(5,2) NULL,\n\t\n\t`break2` decimal(5,2) NULL,\n\t\n\t`break3` decimal(5,2) NULL,\n\t\n\t`break4` decimal(5,2) NULL,\n\t\n\t`break5` decimal(5,2) NULL,\n\t\n\t`break6` decimal(5,2) NULL,\n\t\n\t`break7` decimal(5,2) NULL,\n\t`price1` decimal(10,2) NULL,`price2` decimal(10,2) NULL,`price3` decimal(10,2) NULL,`price4` decimal(10,2) NULL,`price5` decimal(10,2) NULL,`price6` decimal(10,2) NULL,`price7` decimal(10,2) NULL,\n\t   `text` varchar(254) NULL,\n\t   `type` varchar(4) NULL,\n  PRIMARY KEY (`uid`)\n  \n) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
$results = $db->Query($sql);
if (!$results) {
    die('Error contacting database!' . $sql);
}
// open in read-write mode
if (function_exists('dbase_open')) {
    // only if php was compiled with dbase support
    $updatemsg .= "Packing database.<br/>";
    $dbo = dbase_open('datastore/hkmatrix.dbf', 2);
示例#2
0
文件: example.php 项目: kimai/kimai
// (Also note that you can fill in the variables in the top of the class
// if you want to automatically connect when the object is created. If
// 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 -----------------------------
示例#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;
 }