gpt4 book ai didi

php - 1小时后执行查询

转载 作者:太空宇宙 更新时间:2023-11-03 10:45:09 25 4
gpt4 key购买 nike

附上表格样本。 enter image description here

每小时我都想将最新的项目添加到我的表中。该表是从另一个来源填充的,我需要跟踪我收到的最后一个 ID 是什么,并获取此后添加的所有新项目。

$check5 = "select * from media_ids";
$rs5 = mysqli_query($con,$check5);
if(mysqli_num_rows($rs5)==1)
{
$row = mysqli_fetch_assoc($rs5);
$media_id=$row['media_id'];
}

// execute query

最佳答案

  1. 您需要创建一个每小时运行一次的 cronjob。

crontab -e 然后添加0 * * * * php/path/to/script/script.php

  1. 在您的表中添加一个名为 created 的列,将类型设置为 TIMESTAMP,将默认值设置为 CURRENT_TIMESTAMP

3a。 -- 获取最后一小时内的所有内容script.php 应如下所示:

<?php

$current = time() - 3600;
$currentMediaQuery = "select media_id from media_ids where created > {$current}"
$mediaQuery = mysqli_query($con, $currentMediaQuery);

if (mysqli_num_rows($mediaQuery) > 0) {
while ($row = mysqli_fetch_row($mediaQuery)) {
... do stuff
}
}

3b。取10,按要求维护一个指针

<?php

$lastPointer = “select pointer from pointer_tracking”;
$lastPointerResult = mysqli_query($con, $lastPointer);
$lastPointer = mysqli_fetch_row($lastPointerResult)
$lastPointer = $lastPointer[0];

$currentMediaQuery = “select * from media_ids where id > {$lastPointer} limit {$lastPointer}, {$lastPointer +10}”;

$mediaQuery = mysqli_query($con, $currentMediaQuery);

if (mysqli_num_rows($mediaQuery) > 0) {
while ($row = mysqli_fetch_row($mediaQuery)) {
do stuff…
}
}

if (($lastPointer + 10 > 40) {
$lastPointer = 1;
} else {
$lastPointer += 10;
}

mysqli_query($con, “update pointer_tracking set pointer = {$lastPointer}”);

您需要创建一个名为 pointer_tracker 的表,其中包含 id 和 pointer 列,均为整数类型

关于php - 1小时后执行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32920500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com