mindwarpltd
asked on
Why does my php / mysql code work differently when cron'd ?
Please see my script below.
If I run the script in my browser it works fine. if cron't it doesn't
It seems like the delete query isn't working.
The page which relies on the data shows twice as much data as it should, a duplicate of every record.
Any ideas?
If I run the script in my browser it works fine. if cron't it doesn't
It seems like the delete query isn't working.
The page which relies on the data shows twice as much data as it should, a duplicate of every record.
Any ideas?
<?php
list($usec, $sec) = explode(' ',microtime());
$querytime_before = ((float)$usec + (float)$sec);
include "../php/_con.php";
include "../php/_stdfuncs.php";
populate_front_temp_table();
list($usec, $sec) = explode(' ',microtime());
$querytime_after = ((float)$usec + (float)$sec);
$querytime = $querytime_after - $querytime_before;
$strQueryTime = '%01.4f';
echo sprintf($strQueryTime, $querytime);
function populate_front_temp_table() {
global $server;
global $db;
global $user;
global $pass;
global $sBlankMySQLDate;
$con = mysql_connect($server,$user,$pass);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
else {
mysql_select_db($db, $con);
$sql = "DELETE FROM TEMP_FRONT;";
mysql_query($sql) or die('Error, delete query failed');
$sql = "INSERT INTO TEMP_FRONT(section, PadID, CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL) SELECT 1, Pads.PadID, Pads.CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL FROM `Pads` INNER JOIN `Downloads_Count` ON `Downloads_Count`.`CatID` = `Pads`.`CatID` AND `Downloads_count`.`PadID` = `Pads`.`PadID` WHERE `Downloads_Count`.`CatID` = 11 AND `Pads`.`ProgramName` LIKE '%DVD%' AND `Pads`.`License` = 'Freeware' AND RemoveMeDate='" . $sBlankMySQLDate . "' ORDER BY `Downloads_Count`.`tot_downs` DESC LIMIT 0 , 5;";
mysql_query($sql) or die('Error, insert query failed 11');
$sql = "INSERT INTO TEMP_FRONT(section, PadID, CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL) SELECT 2, Pads.PadID, Pads.CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL FROM `Pads` INNER JOIN `Downloads_Count` ON `Downloads_Count`.`CatID` = `Pads`.`CatID` AND `Downloads_count`.`PadID` = `Pads`.`PadID` WHERE `Downloads_Count`.`CatID` = 120 AND RemoveMeDate='" . $sBlankMySQLDate . "' ORDER BY `Downloads_Count`.`tot_downs` DESC LIMIT 0 , 5;";
mysql_query($sql) or die('Error, insert query failed 120');
$sql = "INSERT INTO TEMP_FRONT(section, PadID, CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL) SELECT 3, Pads.PadID, Pads.CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL FROM `Pads` INNER JOIN `Downloads_Count` ON `Downloads_Count`.`CatID` = `Pads`.`CatID` AND `Downloads_count`.`PadID` = `Pads`.`PadID` WHERE `Downloads_Count`.`CatID` = 120 AND `Pads`.`License` = 'Freeware' AND RemoveMeDate='" . $sBlankMySQLDate . "' ORDER BY `Downloads_Count`.`tot_downs` DESC LIMIT 0 , 5;";
mysql_query($sql) or die('Error, insert query failed 120 free');
$sql = "INSERT INTO TEMP_FRONT(section, PadID, CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL) SELECT 4, Pads.PadID, Pads.CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL FROM `Pads` INNER JOIN `Downloads_Count` ON `Downloads_Count`.`CatID` = `Pads`.`CatID` AND `Downloads_count`.`PadID` = `Pads`.`PadID` WHERE `Downloads_Count`.`CatID` = 15 AND `Pads`.`ProgramName` LIKE '%Help Desk%' AND RemoveMeDate='" . $sBlankMySQLDate . "' ORDER BY `Downloads_Count`.`tot_downs` DESC LIMIT 0 , 5;";
mysql_query($sql) or die('Error, insert query failed 15');
$sql = "INSERT INTO TEMP_FRONT(section, PadID, CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL) SELECT 5, Pads.PadID, Pads.CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL FROM `Pads` INNER JOIN `Downloads_Count` ON `Downloads_Count`.`CatID` = `Pads`.`CatID` AND `Downloads_count`.`PadID` = `Pads`.`PadID` WHERE `Downloads_Count`.`CatID` = 9 AND `Pads`.`ProgramName` LIKE '%DVD Ripper%' AND RemoveMeDate='" . $sBlankMySQLDate . "' ORDER BY `Downloads_Count`.`tot_downs` DESC LIMIT 0 , 5;";
mysql_query($sql) or die('Error, insert query failed 9');
}
mysql_close($con);
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, hyarion is right.
That is probably the case. As the cron server doesn't activate the $_SERVER[DOCUMENT_ROOT] variable as
mentioned in the link I provided.
Regards,
Tomas Helgi
That is probably the case. As the cron server doesn't activate the $_SERVER[DOCUMENT_ROOT] variable as
mentioned in the link I provided.
Regards,
Tomas Helgi
ASKER
OK, I've added the full path.
Its a windows server, so I don't think the file permissions will be a problem.
Do you think theres anything else I can try?
Its a windows server, so I don't think the file permissions will be a problem.
Do you think theres anything else I can try?
ASKER
I think thats worked
Is your cronjob setup correctly ?
http://www.modwest.com/help/kb5-125.html
Other does the db-user have delete privileges on the table ?
Check the hosts that the user is allowed to connect from and see
if the delete privileges are on all hosts.
Regards,
Tomas Helgi