Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

need small help with an truncate script


Guest

Recommended Posts

Posted

I have one table in the database i would like to truncate each midnight, my hoster does not allow crontab as you would normalt think, but i can create a php script that can be run almost like crontab

 

script

<?php

//configuration
define('SECURITY_CODE', '******');
define('SALT', '_*******_');

//security check
if(isset($_GET['sc'])){
    $to_check = SALT . $_GET['sc'] . SALT;
    if (md5($to_check)!=SECURITY_CODE){
        exit(0);
    }
} else {
    exit(0);
}

//include base functions
require('includes/application_top.php'); //

// Execute the query.
$result = mysqli_query('TRUNCATE TABLE audit');

if ($result) {
  echo "Audit table has been truncated";  
}
else echo "Something went wrong: " . mysql_error();

?>


of course this does not work and all examples i have found have the database info in the file. For some paranoid reason i dont like that and its also the reason for:

 

 

require('includes/application_top.php'); //

 

 

how can i with php 5.6.20 and MySQL 5.6.29 do the intended without adding database password etc to the file?

5.6.20
Posted

Wont you use tep_db_query() ? mysqli_query() need preconfiguration of database authentication. See http://php.net/manual/en/function.mysqli-connect.php

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Posted

i allready have preconfig in 

 

require('includes/application_top.php'); //

 

 

 

but will go and hunt for some tep_db_query() examples

Posted

should anyone else need this:

<?php

//configuration
define('SECURITY_CODE', '******');
define('SALT', '_*******_');

//security check
if(isset($_GET['sc'])){
    $to_check = SALT . $_GET['sc'] . SALT;
    if (md5($to_check)!=SECURITY_CODE){
        exit(0);
    }
} else {
    exit(0);
}

//include base functions
require('includes/application_top.php'); //

// Execute the query.
$result = tep_db_query('TRUNCATE TABLE audit');

if ($result) {
  echo "Audit table has been truncated";  
}
else echo "Something went wrong: " . mysql_error();

?>

and thanks to @Gergely for giving the pointer

Posted

mysql_error() has no function in last line, because tep_db_query() has error reports.

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...