Jump to content


Photo

set a cron job to execute the SQL periodically


  • Please log in to reply
7 replies to this topic

#1 Hostile

Hostile

    Benefitting Humanity Simply by Showing Up!

  • Veterans
  • 9,551 posts
  • Location:Washington DC
  •  T3A Founder
  • Division:Revora
  • Job:Global Administrator
  • Donated
  • Association

Posted 26 August 2010 - 03:54 PM

SQL = "DELETE FROM table WHERE date_added < " & date()-14

I found this snippet of SQL that I need to run an auto delete record cron job. I have no experience in either. Can anyone help explain how this part works and how it is setup in cpanel?

#2 Beowulf

Beowulf

    Shipgirl

  • Advisors
  • 7,219 posts
  •  Azur Lane Fangirl

Posted 26 August 2010 - 06:54 PM

http://siteground.co...l/cron_jobs.htm
http://www.upstartbl...n-job-in-cpanel
http://www.knowledge...jobs-in-cpanel/

Amazing what google can find. :w00t:

NZ.org | BBPCG
Discord: The Astronomer#1314
Steam


#3 Hostile

Hostile

    Benefitting Humanity Simply by Showing Up!

  • Veterans
  • 9,551 posts
  • Location:Washington DC
  •  T3A Founder
  • Division:Revora
  • Job:Global Administrator
  • Donated
  • Association

Posted 26 August 2010 - 09:11 PM

The sources help with the cron. I was more perplexed on the sql script above so that it is written correctly to automatically delete the records. Where it says
DELETE FROM table
does the word table mean the "name of the table" or is the word table literal? I've googled and there seems to be a lot of different codes to do it. But I'm confused...

#4 Beowulf

Beowulf

    Shipgirl

  • Advisors
  • 7,219 posts
  •  Azur Lane Fangirl

Posted 26 August 2010 - 10:46 PM

DELETE FROM [table_name] WHERE [some condition];

It's pretty simple. But using a delete is kinda... not a good idea sometimes.

NZ.org | BBPCG
Discord: The Astronomer#1314
Steam


#5 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 27 August 2010 - 09:24 AM

does the word table mean the "name of the table" or is the word table literal?

In SQL written by non-sloppy people capitalised words are keywords while the others are names.

What language is the SQL snippet above written in? Assuming MySQL for the SQL and PHP for the bit around, I have an improvement for the query:
DELETE FROM table WHERE date_added < (NOW() - INTERVAL 14 DAYS)
This is assuming you want to delete records older than 14 days. I don't know exactly what the PHP bit "date() - 14" returns, but it's certainly not the time 14 days ago :w00t:
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."

#6 Hostile

Hostile

    Benefitting Humanity Simply by Showing Up!

  • Veterans
  • 9,551 posts
  • Location:Washington DC
  •  T3A Founder
  • Division:Revora
  • Job:Global Administrator
  • Donated
  • Association

Posted 27 August 2010 - 11:32 PM

This is the help that I needed. So table="name of the table to be deleted from" date_added should remain the same. That seems simple enough.

So this snippet of code is all I need to put into the cron?

If I read correctly, I have to put it into a place on the website and write the path to the script. I assume it has to have a php extension?

Thanks...

#7 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 28 August 2010 - 11:13 AM

It doesn't need to be in the website, since cron runs scripts directly, not via the webserver. What you do need to do is connecting to the database in the script.
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."

#8 Hostile

Hostile

    Benefitting Humanity Simply by Showing Up!

  • Veterans
  • 9,551 posts
  • Location:Washington DC
  •  T3A Founder
  • Division:Revora
  • Job:Global Administrator
  • Donated
  • Association

Posted 29 August 2010 - 04:01 AM

I can do that. Good stuff. Thanks...




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users