我正在制作一个重复事件系统,并且必须对检查进行硬编码以查看事件是否已通过以创建新事件。(不,我无法进行 cron 作业,因为系统基础是 Windows,不,我无权访问任务调度程序。)
这是我到目前为止的代码:
<?php
require('common.php');
$query = "SELECT
*
FROM
DD_events
";
try{
$stmt = $db->prepare($query);
$result = $stmt->execute();
}
catch(PDOException $ex){
die("Failed to run query: " . $ex->getMessage());
}
$chk = $stmt->fetchall();
//print_r($chk);
foreach ($chk as $chks) {
if (time() > $chks['event_date']) {
//Add 1 day to event time
$time = strtotime($chks['event_date']);
$newTime = $time + 86400; // 24 * 60 * 60
// Create query to make the next event
$query = "INSERT INTO
DD_events (event_name, event_date, initiator, min_lvl, max_level)
VALUES
({$chks['event_name']}, {$newTime}, 0, {$chks['min_lvl']}, {$chks['max_level']})
";
try
{
// These two statements run the query against your database table.
$stmt = $db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code.
die("Failed to run query: " . $ex->getMessage());
}
}
}
它返回此错误:
Failed to run query: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 200)' at line 4
任何人都可以发现我正在犯的错误,因为我在过去 30 分钟内一直在查看它并且看不到它。