<?php
ini_set('display_errors', 'On');
error_reporting(E_ERROR);

/*The following code updates the TIMESTAMP column in USER_ID table with the current timestamp for a particular user_id*/

function updateTimestamp($user_id){
	// include db config class
	require_once __DIR__ . '/db_config.php';

	// connecting to db
	$mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
	mysqli_set_charset($mysqli, "utf8");
	
	//get timestamp
	$date = new DateTime();
	$ts = $date->getTimestamp();
	
	$stmt = $mysqli->prepare("UPDATE USER_ID SET TIMESTAMP=? WHERE USER_ID = ?");
	$stmt->bind_param("ii", $ts, $user_id);
	$stmt->execute();
	
	// Close the prepared statement.
    	if($stmt != null){
		$stmt->close(); 
	}
	
	mysqli_close($mysqli);
}

?>