Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi2all
i want to automatic delete of mysql tabel data after 5 miuntue how to do that ?

http://pastebin.com/SksY4RZE[^]
Posted
Updated 15-May-13 3:04am
v2
Comments
ZurdoDev 15-May-13 8:47am    
Write code to do it. Where are you stuck?
ZurdoDev 15-May-13 9:35am    
If you are trying to add information to your question then please use the improve question.

1 solution

Well, the tricky part is the "after 5 minutes" requirement. Can you schedule any command on the server - actually this depends on the access level you have and/or the services your hosting partner provides. If not, you can use the "poor man's crone" approach: you don't delete the data exactly after that 5 minutes, but at the first request processing after the expiration of this interval.

The idea is the following in both cases:
1) add a timestamp to your table, and set it on insert to the current timestamp value, let's call it TS:
SQL
CREATE TABLE myTable 
(
 TS TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 
 //rest of the table declaration
);

On insert, just omit this field.
2) when processing any request / or at schedule, just run following command:
SQL
DELETE FROM myTable WHERE TIMESTAMPDIFF(MINUTE,TS,CURRENT_TIMESTAMP)>5 
 
Share this answer
 
Comments
TheSniper105 15-May-13 13:13pm    
not working
Zoltán Zörgő 15-May-13 16:15pm    
What is not working?
TheSniper105 16-May-13 13:24pm    
DELETE FROM myTable WHERE TIMESTAMPDIFF(MINUTE,TS,CURRENT_TIMESTAMP)>5
Zoltán Zörgő 16-May-13 18:34pm    
have you substituted myTable with the table name you use?
have you added the TS field?
what mysql version do you use?
what error message do you get?
have you tried to execute the statement in phpmyadmin or just from code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900