Advertisement
xpppppppaicyber

cronjobAlarm.php

Dec 21st, 2023
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <?php
  2. function checkAndUpdateStatus() {
  3.     // SQLite database file path
  4.     $dbPath = 'alarm.db';
  5.     $botToken = 'ISI TOKEN';
  6.  
  7.     // Connect to SQLite database
  8.     $db = new SQLite3($dbPath);
  9.  
  10.     if (!$db) {
  11.         die("Error connecting to the database.");
  12.     }
  13.  
  14.     // Get the current Unix timestamp
  15.     $currentTimestamp = time();
  16.  
  17.     // Prepare the SQL statement to fetch records where timestamp is less than current time and status is 0
  18.     $stmt = $db->prepare("SELECT * FROM your_table_name WHERE panenTime < :currentTimestamp AND status = 0");
  19.  
  20.     // Bind parameters
  21.     $stmt->bindParam(':currentTimestamp', $currentTimestamp, SQLITE3_INTEGER);
  22.  
  23.     // Execute the statement
  24.     $result = $stmt->execute();
  25.  
  26.     // Check for success
  27.     if ($result) {
  28.         // Fetch the records
  29.         while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
  30.             // Update the status or perform any other action
  31.             $id = $row['id'];
  32.             $userid = $row['userid'];
  33.             $panenTime = date('H:i:s d-m-Y', $row['panenTime']);
  34.             $comment = $row['comment'];
  35.             // $msg = "```yaml\nWaktunya Panen / Claim Energy | $comment | $panenTime```";
  36.             file_get_contents("https://api.telegram.org/bot" . $botToken . "/sendMessage?chat_id=" . $userid . "&text=```yaml Waktunya Panen / Claim Energy | $comment | $panenTime```&parse_mode=markdown");
  37.  
  38.             // Example: Update the status to 1
  39.             $updateStmt = $db->prepare("UPDATE your_table_name SET status = 1 WHERE id = :id");
  40.             $updateStmt->bindParam(':id', $id, SQLITE3_INTEGER);
  41.             $updateStmt->execute();
  42.         }
  43.     } else {
  44.         echo "Error querying database: " . $db->lastErrorMsg();
  45.     }
  46.  
  47.     // Close the database connection
  48.     $db->close();
  49. }
  50.  
  51. checkAndUpdateStatus();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement