TheLettuceMaster
TheLettuceMaster

Reputation: 15744

Set Expiration on MySQL Table Data

In a MySQL Database I am building, I have a column where there is a simple 0 or 1 (true or false) data field. All data is initially set to 0. If a user presses a button on the website I am building, it will change (in the database) from 0 to 1 to show the user as Logged in. I want them to be automatically Logged out by the end of the day (Again, this is accomplished by setting them to 0).

Here is the question: Is there a way to "expire" data after a period of time and set it back to default (or 0)? If so, can it be based on a specific period of time?

If there is any SQL command or method to do this, what about PHP?

Upvotes: 1

Views: 2057

Answers (2)

vidyadhar
vidyadhar

Reputation: 3178

you can use the events (http://dev.mysql.com/doc/refman/5.1/en/events.html) or crontab ( only linux/unix)

Upvotes: 1

s.bandara
s.bandara

Reputation: 5664

Without triggering a procedure you may be out of luck here. However, why don't you do the following: instead of a Boolean use a date and set the date on login. Then, instead of asking if login is true, ask if the login date is the current date. No expiration cleanup necessary, problem solved.

Upvotes: 3

Related Questions