In PHP, mysqli_rollback() undoes the current transaction so none of its uncommitted changes stay on the server.
With an optional savepoint name it can roll back only to that marker instead of the whole transaction. It pairs with begin_transaction(), commit(), savepoint(), and release_savepoint(). Turn autocommit off (or begin explicitly) before you rely on rollback.
Syntax
Call mysqli_rollback() with the values you need. Start with this line.
PHP
$ok = mysqli_rollback($mysql);
Call
What it does
mysqli_rollback($link)
Cancels the open transaction and discards its uncommitted changes.
mysqli_rollback($link, 0, 'sp1')
Rolls back to savepoint sp1 when the server supports it.
$mysqli->rollback()
Object-oriented form for a full transaction rollback.
If autocommit is on and you never began a transaction, rollback has nothing useful to undo. Prefer begin_transaction() for clear boundaries. After a failed statement, check errno/error/sqlstate, then decide whether to rollback.