Forum Moderators: coopster

Message Too Old, No Replies

MySql table row auto deletion after a time interval

         

base

8:15 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



How is it done automatically?
Is it possible using only PHP, without a query, so that it's fully automated?

Thanks in advance.

eelixduppy

8:17 pm on Dec 17, 2008 (gmt 0)



>> without a query

You are going to need to send a query with PHP, but yes it is possible. Create a script that drops the row that you want, then run it though a cron at the time interval that you would like.

base

8:20 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



>>>You are going to need to send a query with PHP, but yes it is possible. Create a script that drops the row that you want, then run it though a cron at the time interval that you would like.

:D yes of course.

how is the cron done exactly?
i've googled it but the answers are not so clear on how to do it exactly

could you make an example?

eelixduppy

8:28 pm on Dec 17, 2008 (gmt 0)



Well if you are running a Unix box, it will be different than that of Windows. Windows uses scheduled tasks, which are pretty self explanatory as how to setup. Unix has Crons. You have to use crontab to change the file. Wikipedia doesn't have that bad of a description of the syntax: [en.wikipedia.org...]

If you still cannot figure it out let me know. But try it first.

note: If you have any relative paths in your PHP script, when using a cron the script isn't going to work as it should, because the working directory has changed. In such a case, you have to use absolute paths.

base

8:33 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



You are aware that I'm trying to do this on a shared host?

eelixduppy

8:35 pm on Dec 17, 2008 (gmt 0)



I was not. If that is the case you might have to talk with your hosting provider. Odds are crons are built into your control panel (if you have one). There should be a place in there, with directions, on how to set something like this up. If this feature isn't supported at all, then I'd suggest switching hosts. :)

base

8:39 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



It's my mistake that I didn't point that out.

I know there is a cron job feature in my admin panel.
I'll look it up, but I was hoping on doing it from scratch.

Thanks eelixduppy.