[PHP-MySQL] MySQL transaction with PHP
// require MySQL Version 4.0.12 using InnoDB type tables.
@mysql_connect("localhost","username", "password") or die(mysql_error());
@mysql_select_db("test") or die(mysql_error());
$query = "INSERT INTO trans (id,item,quantity)
values (null,'Baseball',4)";
begin(); // transaction begins
$result = @mysql_query($query);
if(!$result) {
rollback(); // transaction rolls back
echo "you rolled back";
exit;
} else {
commit(); // transaction is committed
echo "Aggiornamento completato";
}
via DevArticles
See also: