PDO::commit
-- Learning not just technology, but dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
PHP Tutorial
PHP Tutorial PHP Introduction PHP Installation PHP Syntax PHP Variables PHP echo/print PHP EOF(heredoc) PHP Data Types PHP Type Comparison PHP Constants PHP String PHP Operators PHP If...Else PHP Switch PHP Arrays PHP Array Sorting PHP Superglobals PHP While Loop PHP For Loop PHP Functions PHP Magic Constants PHP Namespaces PHP OOP PHP Quiz
PHP Forms
PHP Forms PHP Form Validation PHP Form - Required Fields PHP Form - Validate Email and URL PHP Complete Form Example PHP $_GET Variable PHP $_POST Variable
PHP Advanced Tutorial
PHP Multidimensional Arrays PHP Date PHP Include PHP File PHP File Upload PHP Cookie PHP Session PHP E-mail PHP Secure E-mail PHP Error PHP Exception PHP Filter PHP Advanced Filter PHP JSON
PHP 7 New Features
PHP Database
PHP MySQL Introduction PHP MySQL Connect PHP MySQL Create Database PHP MySQL Create Table PHP MySQL Insert Data PHP MySQL Insert Multiple PHP MySQL Prepared Statements PHP MySQL Select Data PHP MySQL Where PHP MySQL Order By PHP MySQL Update PHP MySQL Delete PHP ODBC
PHP XML
XML Expat Parser XML DOM XML SimpleXML
PHP and AJAX
AJAX Introduction AJAX PHP AJAX Database AJAX XML AJAX Live Search AJAX RSS Reader AJAX Poll
PHP Reference Manual
PHP Array PHP Calendar PHP cURL PHP Date PHP Directory PHP Error PHP Filesystem PHP Filter PHP FTP PHP HTTP PHP Libxml PHP Mail PHP Math PHP Misc PHP MySQLi PHP PDO PHP SimpleXML PHP String PHP XML PHP Zip PHP Timezones PHP Image Processing PHP RESTful PHP PCRE PHP Available Functions PHP Composer
Deep Dive
- Programming
- Web Services
- Scripting Languages
- Web Service
- Software
- Computer Science
- Development Tools
- Programming Languages
- Scripting
- Web Design and Development
PDO::commit
PDO::commit commits a transaction (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)
Description
Syntax
bool PDO::commit ( void )
Commits a transaction. The database connection returns to autocommit mode until the next call to PDO::beginTransaction() starts a new transaction.
Return Values
Returns TRUE on success or FALSE on failure.
Examples
Commit a basic transaction
<?php
/* Begin a transaction, turning off autocommit */
$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 in autocommit mode */
?>
Commit a DDL transaction
<?php
/* Begin a transaction, turning off autocommit */
$dbh->beginTransaction();
/* Change the database schema */
$sth = $dbh->exec("DROP TABLE fruit");
/* Commit the changes */
$dbh->commit();
/* The database connection is now back in autocommit mode */
?>
Note: Not all databases allow transactional operations with DDL statements: some will produce an error, while others (including MySQL) will automatically commit the transaction upon encountering the first DDL statement.
YouTip