From ef51bbad9554137f7784be22150dc98e51a4300d Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Fri, 20 Jul 2012 06:21:14 +0000 Subject: [PATCH] Fix doc bug #62503 (DDL statements in PDO queries are implicitly commited!). git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@326723 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/pdo/pdo/commit.xml | 44 +++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/reference/pdo/pdo/commit.xml b/reference/pdo/pdo/commit.xml index f76d3f3283..52ba20fffc 100644 --- a/reference/pdo/pdo/commit.xml +++ b/reference/pdo/pdo/commit.xml @@ -31,7 +31,41 @@ &reftitle.examples; - Commit a transaction + + Committing a basic transaction + +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(); + +/* Database connection is now back in autocommit mode */ +?> +]]> + + + + + + Committing a DDL transaction commit(); ]]> + + + Not all databases will allow transactions to operate on DDL statements: + some will generate errors, whereas others (including MySQL) will + automatically commit the transaction after the first DDL statement has + been encountered. + +