YouTip LogoYouTip

Pdo Rollback

PDO::rollBack |

-- Learning not just technology, but dreams!

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 Sort 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

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 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 Read 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

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

PHP 5 MySQLi Functions

PHP 5 SimpleXML Functions

PDO::rollBack

PHP PDO ReferencePHP PDO Reference

PDO::rollBack β€” Rolls back a transaction (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)


Description

Syntax

bool PDO::rollBack ( void )

Rolls back the current transaction initiated by PDO::beginTransaction(). If no transaction is active, a PDOException exception is thrown.

If the database is set to autocommit mode, this function (method) will restore autocommit mode after rolling back the transaction.

Some databases, including MySQL, will automatically cause an implicit commit when DDL statements like DROP TABLE or CREATE TABLE are executed within a transaction. An implicit commit makes it impossible to roll back any changes within that transaction scope.


Return Values

Returns TRUE on success, or FALSE on failure.


Example

Rolling Back a Transaction

The following example starts a transaction and issues two statements that modify the database before rolling back the changes. However, in MySQL, the DROP TABLE statement automatically commits the transaction, so any changes within this transaction will not be rolled back.

<?php
/* Begin a transaction, turning off autocommit */
$dbh->beginTransaction();

/* Change the database schema and data */
$sth = $dbh->exec("DROP TABLE fruit");
$sth = $dbh->exec("UPDATE dessert SET name = 'hamburger'");

/* Recognize the error and roll back the changes */
$dbh->rollBack();

/* The database connection will now be restored to autocommit mode */
?>

PHP PDO ReferencePHP PDO Reference

PHP 5 MySQLi Functions

PHP 5 SimpleXML Functions

iFlytek Xingchen Coding Plan includes free model call quotas, DeepSeek, GLM, Kimi, MiniMax, one-stop experience and deployment platform. Configuration Guide Β₯3.9/month Subscribe Now

Click to Share Notes

Cancel

Write notes...

Image URL

Image Description

Image Size Γ—

Share Notes

  • Nickname (Required)
  • Email (Required)
  • Reference URL

Category Navigation

← Pdo SetattributePdo Quote β†’