我似乎无法获得此代码的工作。你可以使用foreach行来运行另一个查询吗?这是一个cron脚本,将发送电子邮件,当cron运行时我需要将状态从'0'更新为'1',因此我知道电子邮件已发送 - 代码为下面的UPDATE查询不起作用。FOREACH和UPDATE mysql不能一起工作
// Connect to the database
$conn = new PDO("mysql:host=$DB_HOST;dbname=$DB_DATABASE",$DB_USER,$DB_PASSWORD);
// Get the emails to send and ensure the status shows they have not been sent already
$stmt = $conn->prepare("SELECT id, userid, title, message FROM reminders WHERE time=CURDATE() AND status='0'");
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($results AS $row){
echo $row['title'] . ' ' . $row['message'] . ' ' . $row['id'] . '<br />';
$update = $conn->prepare("UPDATE results SET status='1' WHERE id=:id");
$update->bindParam(':id', $row['id']);
$update->execute();
};
编辑:表名是错的。解决
这是否会抛出MySql错误或什么? –
它显示正确的行,但不更新状态列。没有错误显示 – cantaffordretail
尝试删除从状态='1'到状态= 1.status的引号可能是一个int列我猜。 –