1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php $connection = mysqli_connect("localhost", "root", "", "hello"); mysqli_autocommit($connection, FALSE); mysqli_query($connection,"INSERT INTO mytestdata (Name,City,Age) VALUES ('Vasanthan','Mangalore',32)"); mysqli_query($connection,"INSERT INTO mytestdata (Name,City,Age) VALUES ('Martin','USA',33)"); mysqli_commit($connection); mysqli_query($connection, "DELETE FROM mytestdata"); if ($result = mysqli_query($connection, "SELECT COUNT(*) FROM mytestdata")) { $row = mysqli_fetch_row($result); printf("%d rows in table mytestdata.\n", $row[0]); mysqli_free_result($result); } mysqli_rollback($connection); if ($result = mysqli_query($connection, "SELECT COUNT(*) FROM mytestdata")) { $row = mysqli_fetch_row($result); printf("%d rows in table mytestdata (after rollback).\n", $row[0]); mysqli_free_result($result); } mysqli_query($connection, "DROP TABLE myCity"); mysqli_close($connection); //output of this code will be like 0 rows in table mytestdata. 2 rows in table mytestdata (after rollback). ?> |