<?php
header('Content-type: application/json');
date_default_timezone_set("Asia/Bangkok");

$servername = "public.05z3l.bkk1.database-hosting.webstarterz.com";
$username = "05z3l_linebot2";
$password = "@Anont0811045107";
$dbname = "05z3l_linebot";

function update(){
	global $servername;
	global $username;
	global $password;
	global $dbname;
	sleep(60);
	// Create connection
	 $conn = new mysqli($servername, $username, $password, $dbname);
	// Check connection
	if ($conn->connect_error) {
	    die("Connection failed: " . $conn->connect_error);
	}
	$sql = "UPDATE monitor SET Counter=Counter+1  WHERE Status = 'EXIT'";
	if ($conn->query($sql) === TRUE) {
	    echo "Record updated successfully";
	} else {
	    echo "Error updating record: " . $conn->error;
	}

	$conn->close();

}

while (true) {
	$date = date('Y-m-d H:i:s');
	echo $date."\n";
	update();
}
?>
