I have 3 php scripts: in 1st one I create a temporary table (in MySQL) with name based on User ID, in 2nd I use that table and give a message to the user, in the 3rd one I use and delete temporary table and give message to the user. My problem is that if user closes browser when he/she is on the 2nd page, I’m left with a temporary table in the database that needs to be dropped. What’s the best way to solve this?
Asked
Active
Viewed 761 times
1
-
have a scheduled job that deletes temp databases that haven't been used in a certain period, or when the user logs out? – Marc B Oct 25 '12 at 15:56
-
Try to get rid of temporary tables – JvdBerg Oct 25 '12 at 15:59
-
Is it truly a temporary table or is that your description? IE 'create temporary table foo... ' – ethrbunny Oct 25 '12 at 16:09
2 Answers
3
This is very poor practice. Create the table ONCE and insert/delete rows based on user actions. Use a timestamp on each row and have a cleanup script run periodically to remove old entries.

Sammitch
- 30,782
- 7
- 50
- 77
0
If you use a common DB handle for all the access you could use 'create temporary table <contents>' and it would be deleted automatically when the handle is closed. This would clean up the mess should the session get closed prematurely.

ethrbunny
- 10,379
- 9
- 69
- 131