我创建了一个脚本,可以从数据库中获取所有销售额,并比较销售中的剩余天数是negative
还是less than 0.2
,然后它会将status
列更新为{{ 1}}。它运行得很好!
Inactive
现在我必须在我的托管中运行此脚本。我面前有这个小组
我将运行此脚本<?php
include_once '../includes/db_connect.php';
$stmtgetallsales = $mysqli->prepare("SELECT * FROM store_sales");
$stmtgetallsales->execute();
$getallsales = $stmtgetallsales->get_result();
$stmtgetallsales->close();
while ($allsales = $getallsales->fetch_assoc()) {
$db_date = join('-',array_reverse(explode('-',$allsales['sale_till'])))." ".$allsales['created_time'];
$check = get_date($db_date);
if ($check < 0 || $check <= 0.2) {
$stmtupdatesale = $mysqli->prepare("UPDATE store_sales SET status='Inactive' WHERE sale_id = ?");
$stmtupdatesale->bind_param("i", $allsales['sale_id']);
$stmtupdatesale->execute();
$stmtupdatesale->close();
}
}
function get_date($old) {
$offset=5*60*60;
$timeFormat="H:i";
$time=gmdate($timeFormat, time()+$offset);
$now = date("Y-m-d");
$dateOldd = $now." ".$time;
$dateCurrent = new DateTime($dateOldd);
$dateNew = new DateTime($old);
$difference_in_seconds = $dateNew->getTimestamp() - $dateCurrent->getTimestamp();
return $total_difference_in_days = $difference_in_seconds / 86400;
}
?>
我应该在once per hour every 24 hours every day
行添加什么设置以及写什么。
我是cronjob的新手。谢谢你的帮助!
答案 0 :(得分:0)
如果是php 5.6
/opt/php56/bin/php /home/username/public_html/cron.php