<?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 _users(){
	global $servername;
	global $username;
	global $password;
	global $dbname;

	// Create connection
	 $conn = new mysqli($servername, $username, $password, $dbname);
	// Check connection
	if ($conn->connect_error) {
	    die("Connection failed: " . $conn->connect_error);
	}

	$sql = "SELECT groupline_name,groupline_api_key,groupline_key_notify,groupline_theme,groupline_date_access,groupline_products,groupline_block,groupline_over_alert,groupline_encode,groupline_highlight,groupline_text FROM groupline WHERE groupline_access='active'";

	$result = $conn->query($sql);
	$res = [];
	if ($result->num_rows > 0) {
	    // output data of each row
	    while($row = $result->fetch_assoc()) {
					array_push($res,$row);
	    }
	} else {
	    echo "Online 100%";
	}
	return $res;
}


echo json_encode(_users());

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