0

The situation: i make some changes in the database, then do some code and then return to the initial values ​​of the affected rows. Is it possible to restore rows to the recent values after changes with some function?

As i see it now: read all the data into an array, then perform the necessary changes and return an array of all the data back.

user1564141
  • 5,911
  • 5
  • 21
  • 18

3 Answers3

1

Easy way, have a "original_value" and "current_value" in your table and keep "original_value" unchanged.

Use "current_value" for your problem and when you need to restore, update the table to make "current_value" back to "original_value"

0

Is it possible to use Transactions in your code? Take a look at this post PHP + MySQL transactions examples

Community
  • 1
  • 1
Aaron Hathaway
  • 4,280
  • 2
  • 19
  • 17
0

If you're using InnoDB or other engines that support transactions, you can do:

mysql_query('SET AUTOCOMMIT=0');
mysql_query('START TRANSACTION');
// TODO make some changes...
mysql_query('ROLLBACK');
mysql_query('SET AUTOCOMMIT=1');
fardjad
  • 20,031
  • 6
  • 53
  • 68