Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Cleaning up

Locked
zazzium
Posts: 84
Joined: Mon Jul 04, 2011 12:52 am

Cleaning up

Unread post by zazzium »

Hi,
I have cronjob that runs once a day. I thought to share the code I use to keep nuBuilder clean.

Code: Select all

include "../db/config.php"; //nuBuilder config file
$conn = mysql_connect($DBHost, $DBUser, $DBPassword);
mysql_select_db($DBName,$conn);

/**************************************************************  
emptying zzsys_trap and zzsys_variable tables
**************************************************************/
  $sql = "TRUNCATE TABLE zzsys_trap";
  mysql_query($sql); 
  $sql = "TRUNCATE TABLE zzsys_variable";
  mysql_query($sql); 
  
/**************************************************************  
Deleting temp tables
**************************************************************/
$result=mysql_query("SHOW TABLES FROM $DBName ") or die(mysql_error());
if(mysql_num_rows($result)>0)
{
  while($row=mysql_fetch_row($result))
  {
    if(substr($row[0], 0, 3) === '___' && strrev(substr($row[0], 0, 3) === '___'))
    {
        $sql = "DROP TABLE $row[0]";
        mysql_query($sql); 
    }
  }
}
Last edited by zazzium on Wed Sep 05, 2012 3:59 pm, edited 1 time in total.
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Cleaning up

Unread post by admin »

Cool,

We use something similar, I'm sure this will help people.

Steven
forgot
Posts: 42
Joined: Thu Aug 09, 2012 8:52 pm

Re: Cleaning up

Unread post by forgot »

Hello

How do you run this code?
I see it is php code and you can execute it only from browser. Am I right?
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Cleaning up

Unread post by massiws »

forgot,

copy the code in a file named cron.php or what you want.
Upload this file in your server document root (where nuBuilder is).
With your server control panel (cPanel, Plesk, etc) set a cronjob to start every time you want (each day, each week, etc.). The command to start cronjob is like this:

Code: Select all

/usr/bin/wget  http://yourdomain.com/cron.php
More options are possible with wget: in this case Google can be your best friend!

Hope this helps.
forgot
Posts: 42
Joined: Thu Aug 09, 2012 8:52 pm

Re: Cleaning up

Unread post by forgot »

Thank you!
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Cleaning up

Unread post by admin »

.
Locked