<?php
require_once('config.php');


$error_message;
$valid = true;


 $sql_wko_tkn_mst = " select tkn_online,tkn_dvc_id,tkn_token from tkn_mst where tkn_user =? and tkn_online = ? and tkn_site =?";

	$params_wko_tkn_mst = array('TOMMS','1','SMS');		
	$stmt_wko_tkn_mst = sqlsrv_query( $conn, $sql_wko_tkn_mst,$params_wko_tkn_mst);	
			
	if( !$stmt_wko_tkn_mst ) {
		$error_message = "Error Select table (wko_mst)";
		returnError($error_message);
		die( print_r( sqlsrv_errors(), true));
	}
	do {
		 while ($row = sqlsrv_fetch_array($stmt_wko_tkn_mst, SQLSRV_FETCH_ASSOC)) {
		 
		 $tkn_dvc_id = $row['tkn_dvc_id'];
		 $tkn_token []= $row['tkn_token'];
		  $tkn_online = $row['tkn_online'];
		
			 
	   }
	} while ( sqlsrv_next_result($stmt_wko_tkn_mst));       


	if( $sql_wko_tkn_mst ) {
		 sqlsrv_commit( $conn );
		 sqlsrv_close( $conn);	
		 returnData($tkn_token);	
		} else {
		 sqlsrv_rollback( $conn );
		 $error_message = "Transaction rolled back.<br />";
		 returnError($error_message);
		} 
	


function returnData($json){
	
	$returnData = array(
	'status' => 'SUCCESS',
	'message' => 'Successfully',
	'data' => $json);
	
	echo json_encode($returnData);
}

function returnError($error_message){
	$json = array();
	
	$returnData = array(
	'status' => 'Alert',
	'message' => $error_message,
	'data' => $json);	
	
	echo json_encode($returnData);
		
	exit();
}	


?>