问题描述:

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.

网友答案:

Transactions can be used in MySQL if you want to execute multiple statements at the same time. You send BEGIN to start a transaction, then send mysql_query-s for the statements you want to execute. These statements are executed if you now send COMMIT or cancelled without any effect if you send ROLLBACK. So, to your additional question: ROLLBACK aborts the queries you have sent before and reverts to the old value in the database. However, once you have committed, you cannot rollback anymore since the transaction is then complete.

网友答案:

This issues a ROLLBACK statement, which rolls back the current transaction.

网友答案:

mysql_rollback() rolls back the current transaction. I you are unfamiliar with transactions, I would suggest some Wikipedia reading. It is an extremely useful concept.

相关阅读:
Top