简体   繁体   中英

How do I set up a “temporary mysql session” system

i want build "promotional(demo) site"

I want to undo the changes made by the user, if the user closes the web browser .

i can't use BEGIN,ROLLBACK

<?
mysql_connect("localhost", "root", "");
mysql_select_db("db");

mysql_query("BEGIN");

mysql_query("UPDATE settings SET theme_color = 'blue' WHERE id = '1'");

//mysql_query("ROLLBACK");
//mysql_query("COMMIT");

$sorgu = mysql_query("SELECT * FROM settings WHERE id = '1'");
?>

Because not apply other page.

And SQL Restore long way, if i want to make a change.

What can I do for it ?

EDIT

eq tables

theme settings 20-30 set

products and settings 50-100 set

multi_langs very:)

Some another solution will be the temporary tables instead of databases. Many frameworks provide us with a pre-tablename config. During the bootstrap time you could identify a demo login to have a demo table for that user in that section of the website (based on using a special model so the base model class of all model classes must find the demo situation and have a special table name based on what is defined in the child model class). For example if the user started to visit a CMS section some CMS section demo tables will be created for the user in a persistent DEMO database. Next we will remove expired datatables regularly.

You'd need to register actions performed by user, and if they do not eventually confirm their work unit, use it to restore previous state of database. A very convoluted and possibly unreliable thing to do.

Unfortunately each new request from same user will use a new MySQL connection (even with persistent connections, a new MySQL session will be started), so (I think there's no way to do it using MySQL's internal mechanisms.


If this is a site, that should appear 'as new' for each user that visits it, perhaps you could create a new database for each new user and feed it with default data. Then as their session expires, drop the database.

BEGIN and ROLLBACK can't help in your case. Try restore database by cron job for example every 30 minutes.

Hard way - is to make environment for each user, like creating new database for each user session... But this is obviously bad idea :)

You should have all your settings keyed by session/user ID.

When a new user logs in, you create a new set of preferences, and populate them with default values.

The user can change whatever they want. When they logout, you delete the preferences rows associated with that user.

This also solves the problem of concurrent access. Websites need to handle multiple users at the same time. so if you are allowing a user to modify how the site looks, it needs to affect only them, not all the other users on the site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM