• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Transaction problem - ROLLBACK when browser closed

Hello all,

I am using the innoDB engine and have build a basic ecommerce site. I start a transaction for each new visiter and when they add items to their cart the qty of the product in the relevent table (product table) is adjusted accordingly. The transaction is only commited when the order is placed.

My problem is that if the user ends the session (by leaving site etc) and has items in their basket (I do not use cookies) I want the MySQL DB to ROLLBACK so that the products that are in the cart have their orignal quanities.

Please can someone help?



P.s the only table that is of type innodb is the product table so a rollback will only affect the relevant bit.
1 Solution
I think the trouble here is that you have no way of knowing when a user leaves your site (except when pressing an exit-button, but this would lead to an obvious solution...) So what I think you need to do is create a custom session-handler. Here you should register all activities of the client, so that you are certain that the user is still active. Furthermore you would need to write a garbage-collection-script that checks if a session is 'dead': i.e. that the last action of the client is a certain amount of minutes (hours or whatever you want) ago. If this is the case, you reset that particular client with your ROLLBACK, and delete the session from your custom session-database (or file or whatever you use).
You could use the normal php-session handling also. It will generate the PHPSESSIONID for you, and will handle the session. In addition you could keep track of that session (use session_id()). It would be an add-on to your current code in that way, instead of a rewrite... To register an action of the user, you could put some code in a file that is always included, or make a file that is automatically prepended or appended to your code.

Hope this will help.
Kshitij AhujaCommented:
No comment has been added to this question in more than 21 days,so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
[Accept  _Marcel_'s comment]

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Kshitij Ahuja
EE Cleanup Volunteer

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now