Reputation: 237
I have a table in my database called log_events
. In this table there is a column called tags
. If there is a value of "debug
" in that column and the date it was put in the database is more than 30 days, then that entry should be deleted. I will run the script via a cron. How can this be done using PHP please, any ideas?
Thanks for any help, in advance.
Upvotes: 1
Views: 2250
Reputation: 72686
You can run a php script through cron or you can achieve your goal also with a simple BASH script :
#!/bin/bash
mysql -u user -pyourpassword dbname<<EOFMYSQL
DELETE FROM table WHERE tags = 'debug' AND date < DATE_SUB(NOW(), INTERVAL 30 DAYS);
EOFMYSQL
then you can call the script in the crontab event.
Upvotes: 2
Reputation: 2346
The SQL Query should look something like this
DELETE * FROM tbl_name WHERE column_name = 'debug' and created_at < NOW() - INTERVAL 30 DAYS
Upvotes: 2