<?php

function get_app_highest_record($maestro_id, $app_id, $player_id) {
	global $db_conn;

	$query = "
		SELECT MAX(HighestRecord)
		FROM app_highest_record
		WHERE MaestroID = ? AND AppID = ? AND PlayerID = ?;
	";
	$stmt = $db_conn->prepare($query);
	$stmt->bind_param("iii", $maestro_id, $app_id, $player_id);
	$stmt->execute();
	$stmt->bind_result($app_highest_record);
	$stmt->fetch();
	$stmt->close();

	return $app_highest_record;

	// echo "\nget_app_highest_record : $app_highest_record";
}


function remove_app_highest_record($maestro_id, $app_id, $player_id) {
	global $db_conn;

	$query = "
		DELETE FROM app_highest_record
		WHERE MaestroID = ? AND AppID = ? AND PlayerID = ?;
	";
	$stmt = $db_conn->prepare($query);
	$stmt->bind_param("iii", $maestro_id, $app_id, $player_id);
	$stmt->execute();

	// echo "\ndelete_app_highest_record";
}

function insert_app_highest_record($maestro_id, $app_id, $player_id, $app_highest_record) {
	global $db_conn;

	$query = "
		INSERT INTO app_highest_record (MaestroID, PlayerID, AppID, HighestRecord, RecordDateTime)
		VALUES (?, ?, ?, ?, NOW());
	";
	$stmt = $db_conn->prepare($query);
	$stmt->bind_param('iiid', $maestro_id, $player_id, $app_id, $app_highest_record);
	$stmt->execute();

	// echo "\ninsert_app_highest_record";
}

?>