Ask a Question related to PHP Development, Design and Development.
-
ludo #1
cron problem
Hi,
I've got a problem with a cron fucntion.
I have a mysql db which I want to be cleaned every 12 hours. So I decided to
use a cron.
There is a problem. When I execute it, I've got the error:
"Database error: Invalid SQL: DELETE FROM myng_ref_proxad_free_adsl WHERE
id_article IN ()
MySQL Error: 1064 (You have an error in your SQL syntax near ')' at line 1)
Database error: Invalid SQL: DELETE FROM myng_library WHERE lib_art_id IN ()
MySQL Error: 1064 (You have an error in your SQL syntax near ')' at line 1)"
If I try execute it again, it works without any problem.
So why do I have to execute it two times in order not to obtain mysql error?
You could tell me "so execute it two times!"
But the problem is that cron can not do it. It just tries to execute it one
time every 12 hours and it gives an error...
Can you help me?
Thanksfully,
Ludo
This is the script I execute:
<?
// Iniciamos la sesión!!
session_start();
ini_set("max_execution_time",600);
include("../config.php");
// Need DB Connection
$db=new My_db;
$db->connect();
$db2=new My_db;
$db2->connect();
// MyNG setting up...
init();
// Set up the language
modules_get_language();
// Templates
$t = new
Template($_SESSION['conf_system_root']."/themes/".$_SESSION['conf_vis_theme']."/templates/");
// Check if clean up ALL the groups or just the
// configured ones
if($_SESSION['conf_clean_MAX_days'] == 0 &&
$_SESSION['conf_clean_MAX_articles'] == 0){
$query = "SELECT
grp_name,grp_id,grp_num_messages,grp_MAX_articles, grp_MAX_days FROM
myng_newsgroup WHERE grp_MAX_articles != 0 OR grp_MAX_days != 0";
$db->query($query);
// For each newsgroup
while($db->next_record()){
// Articles!
if($db->Record['grp_MAX_articles'] != 0){
// Delete (M - N)articles
// M = articles at the group
// N = MAX Articles
if($db->Record['grp_num_messages'] >
$db->Record['grp_MAX_articles']){
$num_2_delete = ($db->Record['grp_num_messages'] -
$db->Record['grp_MAX_articles']);
}else{
$num_2_delete = 0;
}
//echo $num_2_delete."<br>";
if($num_2_delete != 0){
del_articles($num_2_delete,$db->Record['grp_name']);
}
}
// Days!
if($db->Record['grp_MAX_days'] != 0){
// Get current timestamp
$now = time();
$num_days = $db->Record['grp_MAX_days'];
// Get the limit timestamp
$limit = $now - ($num_days * 24 * 60 * 60);
$group_name = real2table($db->Record['grp_name']);
$query_2 = "SELECT count(*) FROM `"."myng_".$group_name."` WHERE
date < ".$limit;
//echo $query_2;
$db2->query($query_2);
$db2->next_record();
$num_2_delete = $db2->Record[0];
if($num_2_delete != 0){
del_articles($num_2_delete,$db->Record['grp_name']);
}
}
}
}else{
// All the groups !
// Check if we depend on number of days or just articles
// Days!
if($_SESSION['conf_clean_MAX_days'] != 0){
// Get current timestamp
$now = time();
$num_days = $_SESSION['conf_clean_MAX_days'];
// Get the limit timestamp
$limit = $now - ($num_days * 24 * 60 * 60);
// Get all the groups
$query = "SELECT grp_name,grp_id FROM myng_newsgroup";
$db->query($query);
// For each newsgroup
while($db->next_record()){
$group_name = real2table($db->Record['grp_name']);
$query_2 = "SELECT count(*) FROM `"."myng_".$group_name."` WHERE
date < ".$limit;
//echo $query_2;
$db2->query($query_2);
$db2->next_record();
$num_2_delete = $db2->Record[0];
if($num_2_delete != 0){
del_articles($num_2_delete,$db->Record['grp_name']);
}
}
}
// Articles!
if($_SESSION['conf_clean_MAX_articles'] != 0){
// Get all the groups
$query = "SELECT grp_name,grp_id,grp_num_messages FROM myng_newsgroup";
$db->query($query);
// For each newsgroup
while($db->next_record()){
// Delete (M - N)articles
// M = articles at the group
// N = MAX Articles
if($db->Record['grp_num_messages'] >
$_SESSION['conf_clean_MAX_articles']){
$num_2_delete = ($db->Record['grp_num_messages'] -
$_SESSION['conf_clean_MAX_articles']);
}else{
$num_2_delete = 0;
}
if($num_2_delete != 0){
del_articles($num_2_delete,$db->Record['grp_name']);
}
}
}
}
// Check if the cleanup has been FORCED
if(isset($_POST['apply_cleanup']) && $_POST['apply_cleanup'] == "yes"){
// We've done up to now the clean up, just return to the
// refering page
header ("Location: ".$_POST['return_page']);
//echo $_POST['return_page'];
}
?>
ludo Guest
-
cron job
If the cron job run every 15 minute, it will fill up mail box. Does anyone has any idea. Thanks "Davide Bianchi" <davideyeahsure@onlyforfun.net>... -
rsh and cron
I have Ultra 60 with Solaris 2.6, and the rsh always work fine, until recently I foud the rsh does not work on the Ultra 60. But I don't have any... -
cron
Not specific to PHP really, but it all started with a simple PHP script I was automating... I've used cron/crontab on a zillion machines, and it... -
CRON: bad user
Hi all, I just noticed the same messages in the cron-log: ! bad user (root) After reading this topic I looked at the shadow-file. I noticed... -
Problem using cron on SCO 5.0.5
Hi, I have a problem using cron on Compaq Proliant ML-370 O/S SCO 5.0.5.. Jobs have been scheduled for more than 20hrs. Problem is after executing... -
Centurion #2
Re: cron problem
ludo wrote:
These weirdo cron errors are usually because cron isn't loading/passing> Hi,
>
> I've got a problem with a cron fucntion.
> I have a mysql db which I want to be cleaned every 12 hours. So I decided
> to use a cron.
> There is a problem. When I execute it, I've got the error:
>
> "Database error: Invalid SQL: DELETE FROM myng_ref_proxad_free_adsl WHERE
> id_article IN ()
> MySQL Error: 1064 (You have an error in your SQL syntax near ')' at line
> 1) Database error: Invalid SQL: DELETE FROM myng_library WHERE lib_art_id
> IN () MySQL Error: 1064 (You have an error in your SQL syntax near ')' at
> line 1)"
correct environment variables to the script, or is running as the wrong
user.
Cron usually runs as root and so most cron jobs are also run as root. If
your script runs fine running under your user ID, then write a simple
wrapper script and get cron to execute the wrapper instead:
#!/bin/bash
su - your_userID -c "your_mysql_script.php"
Note the little "-" between su and your userID, this tells su to load your
environment before executing the command(s) between the "" after the -c.
The other option might be to run your script as a user cron job. To do
this, just log in as yourself and type "crontab -e" to edit your personal
cron jobs :) These will run (surprise, surprise) as 'you' when executed,
usually negating the need to use a wrapper with root's cron jobs.
man su
man cron
Cheers,
James
--
MESSAGE ACKNOWLEDGED -- The Pershing II missiles have been launched.
Centurion Guest



Reply With Quote

