Easy Tutorial
❮ Func Math Pi Php Getimagesize ❯

PDO::commit

PHP PDO Reference Manual

PDO::commit submits a transaction (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)


Description

Syntax

bool PDO::commit ( void )

Submits a transaction, returning the database connection to auto-commit mode until the next call to PDO::beginTransaction() starts a new transaction.


Return Value


Examples

Submitting a Basic Transaction

<?php
/* Start a transaction, turning off auto-commit */
$dbh->beginTransaction();

/* Insert multiple records on an all-or-nothing basis */
$sql = 'INSERT INTO fruit
    (name, colour, calories)
    VALUES (?, ?, ?)';

$sth = $dbh->prepare($sql);

foreach ($fruits as $fruit) {
    $sth->execute(array(
        $fruit->name,
        $fruit->colour,
        $fruit->calories,
    ));
}

/* Commit the changes */
$dbh->commit();

/* The database connection is now back to auto-commit mode */
?>

Submitting a DDL Transaction

<?php
/* Start a transaction, turning off auto-commit */
$dbh->beginTransaction();

/* Change the database schema */
$sth = $dbh->exec("DROP TABLE fruit");

/* Commit the schema change */
$dbh->commit();

/* The database connection is now back to auto-commit mode */
?>

Note: Not all databases allow transactions to operate with DDL statements: some will generate errors, while others (including MySQL) will automatically commit the transaction upon encountering the first DDL statement.


PHP PDO Reference Manual

❮ Func Math Pi Php Getimagesize ❯