Cron作业脚本不起作用

时间:2016-09-01 21:14:17

标签: php cron

所以基本上我有这个cronjob脚本工作在godaddy PHP 5.4,但在不同的主机它不起作用,尝试不同的PHP版本。我有正确的cron路径,主机支持说我做了,甚至向我提供了日志。也许这个脚本有问题?它基本上为用户帐户添加了能量点。

<?php
include "../core.php";
//Fuel Refill (by default every 10 minutes)

$sqlusers = mysql_query("SELECT * FROM users WHERE banned='No'");
while ($rowuser = mysql_fetch_assoc($sqlusers)) {
    if ($rowuser['fuel'] < $rowuser['fuelcapacity']) {
        $userfuelrefill = mysql_query("UPDATE users SET fuel=fuel+1 WHERE username='$rowuser[username]'");
    }
}

echo '<meta http-equiv="refresh" content="0;url=../garage">';
?>

1 个答案:

答案 0 :(得分:0)

不推荐使用mysql扩展,请尝试使用此PDO方法:

<?php 
require [full/script/path/]core.php;
$PDO = new PDO([INSERT CONNECTION STRING]);
$result = $PDO->query("SELECT * FROM users WHERE banned='No'")->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row)
{
   if ($row['fuel'] < $row['fuelcapacity']) {
     $query = "UPDATE users SET fuel=fuel+1 WHERE username= :username";
     $query = $PDO->prepare($query);
     if ($query->execute(array(':username' => $row[username]))) {
     } else { throw new Exception('SQL Query Failed [' . $query->errorCode . ']'); }
   }
}
echo '<meta http-equiv="refresh" content="0;url=../garage">';

现在当然有一些事情需要替换,比如连接字符串和完整路径,但这应该适用于启用PHP PDO。