1

I created a script that register for news letter. but before accepting this processes the registered mail must be validate. so ... after the registration , the scrip insert data into row for the news_letter thable with this value: reg_mail,val_code,reg_time and ...

Until now , this process is done after registration. The script creates a random code and get NOW() time. It then saves in database.

After that if someone else go to reg page, the script sends a query to database and deletes rows that passed for example 5 hours.

I want to change this process and tell mysql to automatically delete rows that pass specific time without send any query to database.

Is it possible? If so, how can I do that?

Stephan
  • 41,764
  • 65
  • 238
  • 329
Mohsen Rasouli
  • 352
  • 3
  • 9
  • 22

1 Answers1

2

It's not possible. The best you can do with pure mysql is periodically trigger a stored procedure to clean the database.

If you want this kind of feature, you'll have to use other kind of storage (memcached or cassandra for example manage ttl pretty well) or layer of application to keep in memory id to expires (a simple process reading a file in which you write a list of events to expire with a timestamp could be enough).

C4stor
  • 8,355
  • 6
  • 29
  • 47