MySQL::TransactionBegin PHP Method

TransactionBegin() public method

Starts a transaction
public TransactionBegin ( ) : boolean
return boolean Returns TRUE on success or FALSE on error
    public function TransactionBegin()
    {
        $this->ResetError();
        if (!$this->IsConnected()) {
            $this->SetError("No connection");
            return false;
        } else {
            if (!$this->in_transaction) {
                if (!mysqli_query($this->mysql_link, "START TRANSACTION")) {
                    $this->SetError();
                    return false;
                } else {
                    $this->in_transaction = true;
                    return true;
                }
            } else {
                $this->SetError("Already in transaction", -1);
                return false;
            }
        }
    }

Usage Example

コード例 #1
0
ファイル: matrixread.php プロジェクト: onyxnz/quartzpos
<?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);
All Usage Examples Of MySQL::TransactionBegin