= get_max_player_count($maestroAccountType)) { set_error_message("학생을 더 이상 추가할 수 없습니다. (더 많은 학생수로 업그레이드 하세요)"); send_result_fail(); exit; } add_player($maestroID, $playerName, $enterCode); $result = has_player_name($maestroID, $playerName, $enterCode); if($result === null) { set_error_message("학생 등록에 실패했습니다."); send_result_fail(); exit; } // increase_player_count($maestroID, 1); $count = count_registered_player($maestroID); update_count_registered_player($maestroID, $count); set_data("count", $count); send_result_success(); exit; function has_player_name($maestroID, $playerName, $enterCode) { global $db_conn; $query = " SELECT PlayerID FROM player WHERE MaestroID = ? AND Name = ? AND EnterCode = ? "; $stmt = $db_conn->prepare($query); $stmt->bind_param("iss", $maestroID, $playerName, $enterCode); $stmt->execute(); $stmt->bind_result($playerID); // while($stmt->fetch()) $stmt->fetch(); $stmt->close(); return $playerID; } function get_maestro_account_type($maestroID) { global $db_conn; $query = " SELECT AccountType FROM maestro WHERE MaestroID = ? "; $stmt = $db_conn->prepare($query); $stmt->bind_param("i", $maestroID); $stmt->execute(); $stmt->bind_result($accountType); // while($stmt->fetch()) $stmt->fetch(); $stmt->close(); return $accountType; } function get_player_count($maestroID) { global $db_conn; $query = " SELECT PlayerCount FROM maestro WHERE MaestroID = ? "; $stmt = $db_conn->prepare($query); $stmt->bind_param("i", $maestroID); $stmt->execute(); $stmt->bind_result($playerCount); // while($stmt->fetch()) $stmt->fetch(); $stmt->close(); return $playerCount; } function add_player($maestroID, $playerName, $enterCode) { global $db_conn; $query = " INSERT INTO player (MaestroID, Name, EnterCode) VALUES (?, ?, ?) "; $stmt = $db_conn->prepare($query); $stmt->bind_param("iss", $maestroID, $playerName, $enterCode); $stmt->execute(); } function increase_player_count($maestroID, $count) { global $db_conn; $query = " UPDATE maestro SET PlayerCount = PlayerCount + ? WHERE MaestroID = ? "; $stmt = $db_conn->prepare($query); $stmt->bind_param("ii", $count, $maestroID); $stmt->execute(); } function count_registered_player($maestroID) { global $db_conn; $query = " SELECT COUNT(PlayerID) FROM player WHERE MaestroID = ? AND AccountType = 0 "; $stmt = $db_conn->prepare($query); $stmt->bind_param("i", $maestroID); $stmt->execute(); $stmt->bind_result($countPlayer); // while($stmt->fetch()) $stmt->fetch(); $stmt->close(); return $countPlayer; } function update_count_registered_player($maestroID, $countPlayer) { global $db_conn; $query = " UPDATE maestro SET PlayerCount = ? WHERE MaestroID = ? "; $stmt = $db_conn->prepare($query); $stmt->bind_param("ii", $countPlayer, $maestroID); $stmt->execute(); } ?>