array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'es', ), 'this' => array ( 0 => 'mysqli.rollback.php', 1 => 'mysqli::rollback', ), 'up' => array ( 0 => 'class.mysqli.php', 1 => 'mysqli', ), 'prev' => array ( 0 => 'mysqli.release-savepoint.php', 1 => 'mysqli::release_savepoint', ), 'next' => array ( 0 => 'mysqli.savepoint.php', 1 => 'mysqli::savepoint', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'es', 'path' => 'reference/mysqli/mysqli/rollback.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
mysqli::rollback -- mysqli_rollback — Revierte la transacción actual
Estilo orientado a objetos
Estilo por procedimientos
Revierte la transacción actual de la base de datos.
link
Sólo estilo por procediminetos: Un identificador de enlace devuelto por mysqli_connect() o mysqli_init()
flags
Una máscara de bits de constantes MYSQLI_TRANS_COR_*
.
name
Si se proporciona, se ejecuta ROLLBACK/*name*/
.
Versión | Descripción |
---|---|
5.5.0 |
Se añadieron los parámetros flags y
name .
|
Ejemplo #1 Ejemplo de mysqli::rollback()
Estilo orientado a objetos
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* verificar la conexión */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* deshabilitar autocommit */
$mysqli->autocommit(FALSE);
$mysqli->query("CREATE TABLE myCity LIKE City");
$mysqli->query("ALTER TABLE myCity Type=InnoDB");
$mysqli->query("INSERT INTO myCity SELECT * FROM City LIMIT 50");
/* insertar commit */
$mysqli->commit();
/* borrar todas las filas */
$mysqli->query("DELETE FROM myCity");
if ($result = $mysqli->query("SELECT COUNT(*) FROM myCity")) {
$row = $result->fetch_row();
printf("%d rows in table myCity.\n", $row[0]);
/* Liberar resultado */
$result->close();
}
/* Revertir */
$mysqli->rollback();
if ($result = $mysqli->query("SELECT COUNT(*) FROM myCity")) {
$row = $result->fetch_row();
printf("%d rows in table myCity (after rollback).\n", $row[0]);
/* Liberar resultado */
$result->close();
}
/* Eliminar la tabla myCity */
$mysqli->query("DROP TABLE myCity");
$mysqli->close();
?>
Estilo por procedimientos
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* verificar la conexión */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* deshabilitar autocommit */
mysqli_autocommit($link, FALSE);
mysqli_query($link, "CREATE TABLE myCity LIKE City");
mysqli_query($link, "ALTER TABLE myCity Type=InnoDB");
mysqli_query($link, "INSERT INTO myCity SELECT * FROM City LIMIT 50");
/* insertar commit */
mysqli_commit($link);
/* borrar todas las filas */
mysqli_query($link, "DELETE FROM myCity");
if ($result = mysqli_query($link, "SELECT COUNT(*) FROM myCity")) {
$row = mysqli_fetch_row($result);
printf("%d rows in table myCity.\n", $row[0]);
/* Liberar resultado */
mysqli_free_result($result);
}
/* Revertir */
mysqli_rollback($link);
if ($result = mysqli_query($link, "SELECT COUNT(*) FROM myCity")) {
$row = mysqli_fetch_row($result);
printf("%d rows in table myCity (after rollback).\n", $row[0]);
/* Liberar resultado */
mysqli_free_result($result);
}
/* Eliminar la tabla myCity */
mysqli_query($link, "DROP TABLE myCity");
mysqli_close($link);
?>
El resultado de los ejemplos sería:
0 rows in table myCity. 50 rows in table myCity (after rollback).