forked from Saipavan0910/FarmFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.php
44 lines (30 loc) · 1 KB
/
connection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$conn = new mysqli("localhost", "root", "", "new_farmflow");
if($conn->error){
echo "Database Not Working!";
}
$timestampFile = 'last_run.txt';
$lastRun = @file_get_contents($timestampFile);
$currentTime = time();
if (!$lastRun || ($currentTime - $lastRun) > 60) {
$currentTime = time();
$sql = "UPDATE `order` o
INNER JOIN line_item l ON o.order_id = l.order_id
SET o.status = 'Done'
WHERE o.status = 'Placed' AND l.end_date < CURDATE()";
if ($conn->query($sql) === TRUE) {
} else {
}
file_put_contents($timestampFile, $currentTime);
}
$status = mysqli_query($conn, "SELECT * FROM vehicle");
while ($row = mysqli_fetch_assoc($status)){
$vehicle = $row['vehicle_id'];
$date = $row['enddate'];
$currentTimestamp = strtotime(date("Y-m-d"));
$databaseTimestamp = strtotime($date);
if($currentTimestamp > $databaseTimestamp){
$execute = mysqli_query($conn, "DELETE FROM vehicle where vehicle_id = $vehicle");
}
}
?>