<?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_find($api_key){
	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 * FROM groupline WHERE groupline_api_key='".$api_key."'";
	$result = $conn->query($sql);
	$res = [];
	if ($result->num_rows > 0) {
	    while($row = $result->fetch_assoc()) {
					array_push($res,$row);
	    }
	}
	return $res;
}

if(isset($_GET)){
	if(isset($_GET['mid'])){
		$api_key = $_GET['mid'];
		echo json_encode(_users_find($api_key));
	}
}
