Page 1 of 1

Cleaning up

Posted: Thu Aug 02, 2012 2:22 pm
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); 
    }
  }
}

Re: Cleaning up

Posted: Mon Aug 06, 2012 4:07 am
by admin
Cool,

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

Steven

Re: Cleaning up

Posted: Wed Sep 05, 2012 12:54 pm
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?

Re: Cleaning up

Posted: Wed Sep 05, 2012 1:38 pm
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.

Re: Cleaning up

Posted: Wed Sep 05, 2012 3:01 pm
by forgot
Thank you!

Re: Cleaning up

Posted: Thu Sep 06, 2012 7:56 am
by admin
.