What is the use of mysql_rollback() function in PHP?
How is it used?
please explain me with some example,
PS: Please Do not give me link to the php.net or, mysql site, I dont need AUTHOR language to understand it, I need the Developer way to understand…
I hope u understand…
Thanks in advance.
UPDATE
if i have Updated something in a table can I Reset the previous value using this function?
A transaction is a way to ensure either ALL statements succeed, or none do.
For example, to transfer money from Bob’s bank account to Alice, one might do this:
UPDATE accounts SET amount = amount – 100 WHERE name = ‘Bob’;
UPDATE accounts SET amount = amount + 100 WHERE name = ‘Alice’;
But imagine if something goes wrong (server crashes because power goes out) after the first statement. The bank now has deducted 100 dollar from Bob, but Alice got nothing!
To avoid that, we use a transaction. As Etan explained: you first BEGIN, then you execute all statements. If all went well, you then COMMIT. Only then the modifications are saved.
If something goes wrong (eg there is no account for Alice) you can ROLLBACK, or the server will ROLLBACK if something goes seriously wrong (ie power goes down).
To answer your UPDATE
If you have Updated something in a table you can reset the previous value using this function only if you started with BEGIN and did not COMMIT yet, yes.