MySQL::TransactionEnd PHP Method

TransactionEnd() public method

Ends a transaction and commits the queries
public TransactionEnd ( ) : boolean
return boolean Returns TRUE on success or FALSE on error
    public function TransactionEnd()
    {
        $this->ResetError();
        if (!$this->IsConnected()) {
            $this->SetError("No connection");
            return false;
        } else {
            if ($this->in_transaction) {
                if (!mysqli_query($this->mysql_link, "COMMIT")) {
                    // $this->TransactionRollback();
                    $this->SetError();
                    return false;
                } else {
                    $this->in_transaction = false;
                    return true;
                }
            } else {
                $this->SetError("Not in a transaction", -1);
                return false;
            }
        }
    }

Usage Example

Example #1
0
// 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 -------------------------------------
All Usage Examples Of MySQL::TransactionEnd