Actualiser api/player.php
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once 'config.php';
|
require_once 'config.php';
|
||||||
|
|
||||||
$method = $_SERVER['REQUEST_METHOD'];
|
$method = $_SERVER['REQUEST_METHOD'];
|
||||||
$action = $_GET['action'] ?? '';
|
$action = $_GET['action'] ?? '';
|
||||||
$id = $_GET['id'] ?? null;
|
$id = $_GET['id'] ?? null;
|
||||||
@@ -15,29 +14,24 @@ switch ($method) {
|
|||||||
getAllPlayers();
|
getAllPlayers();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'POST':
|
case 'POST':
|
||||||
requireAdmin();
|
requireAdmin();
|
||||||
addPlayer();
|
addPlayer();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'PUT':
|
case 'PUT':
|
||||||
requireAdmin();
|
requireAdmin();
|
||||||
updatePlayer($id);
|
updatePlayer($id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'DELETE':
|
case 'DELETE':
|
||||||
requireAdmin();
|
requireAdmin();
|
||||||
deletePlayer($id);
|
deletePlayer($id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
jsonResponse(['error' => 'Méthode non autorisée'], 405);
|
jsonResponse(['error' => 'Méthode non autorisée'], 405);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllPlayers() {
|
function getAllPlayers() {
|
||||||
$db = getDB();
|
$db = getDB();
|
||||||
|
|
||||||
$stmt = $db->query("
|
$stmt = $db->query("
|
||||||
SELECT p.*,
|
SELECT p.*,
|
||||||
(SELECT GROUP_CONCAT(strength SEPARATOR '|') FROM player_strengths WHERE player_id = p.id) as strengths,
|
(SELECT GROUP_CONCAT(strength SEPARATOR '|') FROM player_strengths WHERE player_id = p.id) as strengths,
|
||||||
@@ -45,26 +39,20 @@ function getAllPlayers() {
|
|||||||
FROM players p
|
FROM players p
|
||||||
ORDER BY p.ranking ASC
|
ORDER BY p.ranking ASC
|
||||||
");
|
");
|
||||||
|
|
||||||
$players = [];
|
$players = [];
|
||||||
while ($row = $stmt->fetch()) {
|
while ($row = $stmt->fetch()) {
|
||||||
$row['strengths'] = $row['strengths'] ? explode('|', $row['strengths']) : [];
|
$row['strengths'] = $row['strengths'] ? explode('|', $row['strengths']) : [];
|
||||||
$row['weaknesses'] = $row['weaknesses'] ? explode('|', $row['weaknesses']) : [];
|
$row['weaknesses'] = $row['weaknesses'] ? explode('|', $row['weaknesses']) : [];
|
||||||
|
|
||||||
// Convertir les décimaux en float
|
|
||||||
$row['clay_win_rate'] = (float)$row['clay_win_rate'];
|
$row['clay_win_rate'] = (float)$row['clay_win_rate'];
|
||||||
$row['hard_win_rate'] = (float)$row['hard_win_rate'];
|
$row['hard_win_rate'] = (float)$row['hard_win_rate'];
|
||||||
$row['grass_win_rate'] = (float)$row['grass_win_rate'];
|
$row['grass_win_rate'] = (float)$row['grass_win_rate'];
|
||||||
|
|
||||||
$players[] = $row;
|
$players[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonResponse(['success' => true, 'players' => $players]);
|
jsonResponse(['success' => true, 'players' => $players]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlayer($id) {
|
function getPlayer($id) {
|
||||||
$db = getDB();
|
$db = getDB();
|
||||||
|
|
||||||
$stmt = $db->prepare("
|
$stmt = $db->prepare("
|
||||||
SELECT p.*,
|
SELECT p.*,
|
||||||
(SELECT GROUP_CONCAT(strength SEPARATOR '|') FROM player_strengths WHERE player_id = p.id) as strengths,
|
(SELECT GROUP_CONCAT(strength SEPARATOR '|') FROM player_strengths WHERE player_id = p.id) as strengths,
|
||||||
@@ -74,25 +62,19 @@ function getPlayer($id) {
|
|||||||
");
|
");
|
||||||
$stmt->execute([$id]);
|
$stmt->execute([$id]);
|
||||||
$player = $stmt->fetch();
|
$player = $stmt->fetch();
|
||||||
|
|
||||||
if (!$player) {
|
if (!$player) {
|
||||||
jsonResponse(['error' => 'Joueur non trouvé'], 404);
|
jsonResponse(['error' => 'Joueur non trouvé'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$player['strengths'] = $player['strengths'] ? explode('|', $player['strengths']) : [];
|
$player['strengths'] = $player['strengths'] ? explode('|', $player['strengths']) : [];
|
||||||
$player['weaknesses'] = $player['weaknesses'] ? explode('|', $player['weaknesses']) : [];
|
$player['weaknesses'] = $player['weaknesses'] ? explode('|', $player['weaknesses']) : [];
|
||||||
|
|
||||||
jsonResponse(['success' => true, 'player' => $player]);
|
jsonResponse(['success' => true, 'player' => $player]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMatchupAnalysis($player1Id, $player2Id) {
|
function getMatchupAnalysis($player1Id, $player2Id) {
|
||||||
$db = getDB();
|
$db = getDB();
|
||||||
|
|
||||||
// Récupérer les deux joueurs
|
|
||||||
$stmt = $db->prepare("SELECT * FROM players WHERE id = ?");
|
$stmt = $db->prepare("SELECT * FROM players WHERE id = ?");
|
||||||
$stmt->execute([$player1Id]);
|
$stmt->execute([$player1Id]);
|
||||||
$player1 = $stmt->fetch();
|
$player1 = $stmt->fetch();
|
||||||
|
|
||||||
$stmt = $db->prepare("SELECT * FROM players WHERE id = ?");
|
$stmt = $db->prepare("SELECT * FROM players WHERE id = ?");
|
||||||
$stmt->execute([$player2Id]);
|
$stmt->execute([$player2Id]);
|
||||||
$player2 = $stmt->fetch();
|
$player2 = $stmt->fetch();
|
||||||
@@ -100,12 +82,9 @@ function getMatchupAnalysis($player1Id, $player2Id) {
|
|||||||
if (!$player1 || !$player2) {
|
if (!$player1 || !$player2) {
|
||||||
jsonResponse(['error' => 'Un ou les deux joueurs n\'existent pas'], 404);
|
jsonResponse(['error' => 'Un ou les deux joueurs n\'existent pas'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupérer les forces et faiblesses
|
|
||||||
$stmt = $db->prepare("SELECT strength FROM player_strengths WHERE player_id = ?");
|
$stmt = $db->prepare("SELECT strength FROM player_strengths WHERE player_id = ?");
|
||||||
$stmt->execute([$player1Id]);
|
$stmt->execute([$player1Id]);
|
||||||
$player1['strengths'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
$player1['strengths'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
$stmt = $db->prepare("SELECT weakness FROM player_weaknesses WHERE player_id = ?");
|
$stmt = $db->prepare("SELECT weakness FROM player_weaknesses WHERE player_id = ?");
|
||||||
$stmt->execute([$player1Id]);
|
$stmt->execute([$player1Id]);
|
||||||
$player1['weaknesses'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
$player1['weaknesses'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
@@ -113,18 +92,13 @@ function getMatchupAnalysis($player1Id, $player2Id) {
|
|||||||
$stmt = $db->prepare("SELECT strength FROM player_strengths WHERE player_id = ?");
|
$stmt = $db->prepare("SELECT strength FROM player_strengths WHERE player_id = ?");
|
||||||
$stmt->execute([$player2Id]);
|
$stmt->execute([$player2Id]);
|
||||||
$player2['strengths'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
$player2['strengths'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
$stmt = $db->prepare("SELECT weakness FROM player_weaknesses WHERE player_id = ?");
|
$stmt = $db->prepare("SELECT weakness FROM player_weaknesses WHERE player_id = ?");
|
||||||
$stmt->execute([$player2Id]);
|
$stmt->execute([$player2Id]);
|
||||||
$player2['weaknesses'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
$player2['weaknesses'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
// Calculer les probabilités
|
|
||||||
$probabilities = calculateWinProbability($player1, $player2, 'clay');
|
$probabilities = calculateWinProbability($player1, $player2, 'clay');
|
||||||
|
|
||||||
// Analyser le matchup
|
|
||||||
$analysis = analyzeMatchup($player1, $player2);
|
$analysis = analyzeMatchup($player1, $player2);
|
||||||
|
|
||||||
// Récupérer H2H si disponible
|
|
||||||
$stmt = $db->prepare("
|
$stmt = $db->prepare("
|
||||||
SELECT * FROM head_to_head
|
SELECT * FROM head_to_head
|
||||||
WHERE (player1_id = ? AND player2_id = ?)
|
WHERE (player1_id = ? AND player2_id = ?)
|
||||||
@@ -146,29 +120,19 @@ function getMatchupAnalysis($player1Id, $player2Id) {
|
|||||||
function calculateWinProbability($player1, $player2, $surface = 'clay') {
|
function calculateWinProbability($player1, $player2, $surface = 'clay') {
|
||||||
$prob1 = 50;
|
$prob1 = 50;
|
||||||
$prob2 = 50;
|
$prob2 = 50;
|
||||||
|
|
||||||
// Facteur ranking
|
|
||||||
$rankingDiff = $player2['ranking'] - $player1['ranking'];
|
$rankingDiff = $player2['ranking'] - $player1['ranking'];
|
||||||
$prob1 += $rankingDiff * 2;
|
$prob1 += $rankingDiff * 2;
|
||||||
$prob2 -= $rankingDiff * 2;
|
$prob2 -= $rankingDiff * 2;
|
||||||
|
|
||||||
// Facteur surface
|
|
||||||
$surfaceField = $surface . '_win_rate';
|
$surfaceField = $surface . '_win_rate';
|
||||||
$p1Surface = $player1[$surfaceField] * 100;
|
$p1Surface = $player1[$surfaceField] * 100;
|
||||||
$p2Surface = $player2[$surfaceField] * 100;
|
$p2Surface = $player2[$surfaceField] * 100;
|
||||||
$surfaceDiff = $p1Surface - $p2Surface;
|
$surfaceDiff = $p1Surface - $p2Surface;
|
||||||
$prob1 += $surfaceDiff * 0.5;
|
$prob1 += $surfaceDiff * 0.5;
|
||||||
$prob2 -= $surfaceDiff * 0.5;
|
$prob2 -= $surfaceDiff * 0.5;
|
||||||
|
|
||||||
// Normalisation
|
|
||||||
$total = $prob1 + $prob2;
|
$total = $prob1 + $prob2;
|
||||||
$prob1 = round(($prob1 / $total) * 100);
|
$prob1 = round(($prob1 / $total) * 100);
|
||||||
$prob2 = 100 - $prob1;
|
|
||||||
|
|
||||||
// Limiter entre 10 et 90
|
|
||||||
$prob1 = max(10, min(90, $prob1));
|
$prob1 = max(10, min(90, $prob1));
|
||||||
$prob2 = 100 - $prob1;
|
$prob2 = 100 - $prob1;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'player1' => $prob1,
|
'player1' => $prob1,
|
||||||
'player2' => $prob2
|
'player2' => $prob2
|
||||||
@@ -182,21 +146,16 @@ function analyzeMatchup($player1, $player2) {
|
|||||||
'player2_advantages' => [],
|
'player2_advantages' => [],
|
||||||
'player2_disadvantages' => []
|
'player2_disadvantages' => []
|
||||||
];
|
];
|
||||||
|
|
||||||
// Analyser les forces
|
|
||||||
foreach ($player1['strengths'] as $strength) {
|
foreach ($player1['strengths'] as $strength) {
|
||||||
if (!in_array($strength, $player2['strengths']) && !in_array($strength, $player2['weaknesses'])) {
|
if (!in_array($strength, $player2['strengths']) && !in_array($strength, $player2['weaknesses'])) {
|
||||||
$analysis['player1_advantages'][] = $strength;
|
$analysis['player1_advantages'][] = $strength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($player2['strengths'] as $strength) {
|
foreach ($player2['strengths'] as $strength) {
|
||||||
if (!in_array($strength, $player1['strengths']) && !in_array($strength, $player1['weaknesses'])) {
|
if (!in_array($strength, $player1['strengths']) && !in_array($strength, $player1['weaknesses'])) {
|
||||||
$analysis['player2_advantages'][] = $strength;
|
$analysis['player2_advantages'][] = $strength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exploitation des faiblesses
|
|
||||||
foreach ($player1['weaknesses'] as $weakness) {
|
foreach ($player1['weaknesses'] as $weakness) {
|
||||||
foreach ($player2['strengths'] as $strength) {
|
foreach ($player2['strengths'] as $strength) {
|
||||||
if (stripos($strength, explode(' ', $weakness)[0]) !== false) {
|
if (stripos($strength, explode(' ', $weakness)[0]) !== false) {
|
||||||
@@ -205,7 +164,6 @@ function analyzeMatchup($player1, $player2) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($player2['weaknesses'] as $weakness) {
|
foreach ($player2['weaknesses'] as $weakness) {
|
||||||
foreach ($player1['strengths'] as $strength) {
|
foreach ($player1['strengths'] as $strength) {
|
||||||
if (stripos($strength, explode(' ', $weakness)[0]) !== false) {
|
if (stripos($strength, explode(' ', $weakness)[0]) !== false) {
|
||||||
@@ -214,28 +172,23 @@ function analyzeMatchup($player1, $player2) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $analysis;
|
return $analysis;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPlayer() {
|
function addPlayer() {
|
||||||
$data = getJsonInput();
|
$data = getJsonInput();
|
||||||
|
|
||||||
$required = ['player_code', 'name', 'nationality', 'age', 'handedness', 'ranking', 'points'];
|
$required = ['player_code', 'name', 'nationality', 'age', 'handedness', 'ranking', 'points'];
|
||||||
foreach ($required as $field) {
|
foreach ($required as $field) {
|
||||||
if (!isset($data[$field])) {
|
if (!isset($data[$field])) {
|
||||||
jsonResponse(['error' => "Le champ $field est requis"], 400);
|
jsonResponse(['error' => "Le champ $field est requis"], 400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$db = getDB();
|
$db = getDB();
|
||||||
|
|
||||||
$stmt = $db->prepare("
|
$stmt = $db->prepare("
|
||||||
INSERT INTO players (player_code, name, nationality, age, handedness, photo_url, ranking, points,
|
INSERT INTO players (player_code, name, nationality, age, handedness, photo_url, ranking, points,
|
||||||
clay_win_rate, hard_win_rate, grass_win_rate)
|
clay_win_rate, hard_win_rate, grass_win_rate)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
");
|
");
|
||||||
|
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
$data['player_code'],
|
$data['player_code'],
|
||||||
$data['name'],
|
$data['name'],
|
||||||
@@ -249,86 +202,66 @@ function addPlayer() {
|
|||||||
$data['hard_win_rate'] ?? 0.50,
|
$data['hard_win_rate'] ?? 0.50,
|
||||||
$data['grass_win_rate'] ?? 0.50
|
$data['grass_win_rate'] ?? 0.50
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$playerId = $db->lastInsertId();
|
$playerId = $db->lastInsertId();
|
||||||
|
|
||||||
// Ajouter les forces
|
|
||||||
if (isset($data['strengths']) && is_array($data['strengths'])) {
|
if (isset($data['strengths']) && is_array($data['strengths'])) {
|
||||||
$stmt = $db->prepare("INSERT INTO player_strengths (player_id, strength) VALUES (?, ?)");
|
$stmt = $db->prepare("INSERT INTO player_strengths (player_id, strength) VALUES (?, ?)");
|
||||||
foreach ($data['strengths'] as $strength) {
|
foreach ($data['strengths'] as $strength) {
|
||||||
$stmt->execute([$playerId, $strength]);
|
$stmt->execute([$playerId, $strength]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajouter les faiblesses
|
|
||||||
if (isset($data['weaknesses']) && is_array($data['weaknesses'])) {
|
if (isset($data['weaknesses']) && is_array($data['weaknesses'])) {
|
||||||
$stmt = $db->prepare("INSERT INTO player_weaknesses (player_id, weakness) VALUES (?, ?)");
|
$stmt = $db->prepare("INSERT INTO player_weaknesses (player_id, weakness) VALUES (?, ?)");
|
||||||
foreach ($data['weaknesses'] as $weakness) {
|
foreach ($data['weaknesses'] as $weakness) {
|
||||||
$stmt->execute([$playerId, $weakness]);
|
$stmt->execute([$playerId, $weakness]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonResponse(['success' => true, 'message' => 'Joueur ajouté avec succès', 'player_id' => $playerId]);
|
jsonResponse(['success' => true, 'message' => 'Joueur ajouté avec succès', 'player_id' => $playerId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePlayer($id) {
|
function updatePlayer($id) {
|
||||||
$data = getJsonInput();
|
$data = getJsonInput();
|
||||||
$db = getDB();
|
$db = getDB();
|
||||||
|
|
||||||
// Vérifier que le joueur existe
|
|
||||||
$stmt = $db->prepare("SELECT id FROM players WHERE id = ?");
|
$stmt = $db->prepare("SELECT id FROM players WHERE id = ?");
|
||||||
$stmt->execute([$id]);
|
$stmt->execute([$id]);
|
||||||
if (!$stmt->fetch()) {
|
if (!$stmt->fetch()) {
|
||||||
jsonResponse(['error' => 'Joueur non trouvé'], 404);
|
jsonResponse(['error' => 'Joueur non trouvé'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->beginTransaction();
|
$db->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$fields = [];
|
$fields = [];
|
||||||
$values = [];
|
$values = [];
|
||||||
|
|
||||||
$allowedFields = ['name', 'nationality', 'age', 'handedness', 'photo_url', 'ranking', 'points',
|
$allowedFields = ['name', 'nationality', 'age', 'handedness', 'photo_url', 'ranking', 'points',
|
||||||
'clay_win_rate', 'hard_win_rate', 'grass_win_rate'];
|
'clay_win_rate', 'hard_win_rate', 'grass_win_rate'];
|
||||||
|
|
||||||
foreach ($allowedFields as $field) {
|
foreach ($allowedFields as $field) {
|
||||||
if (isset($data[$field])) {
|
if (isset($data[$field])) {
|
||||||
$fields[] = "$field = ?";
|
$fields[] = "$field = ?";
|
||||||
$values[] = $data[$field];
|
$values[] = $data[$field];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($fields)) {
|
if (!empty($fields)) {
|
||||||
$values[] = $id;
|
$values[] = $id;
|
||||||
$stmt = $db->prepare("UPDATE players SET " . implode(', ', $fields) . " WHERE id = ?");
|
$stmt = $db->prepare("UPDATE players SET " . implode(', ', $fields) . " WHERE id = ?");
|
||||||
$stmt->execute($values);
|
$stmt->execute($values);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mettre à jour les forces si fourni
|
|
||||||
if (isset($data['strengths'])) {
|
if (isset($data['strengths'])) {
|
||||||
$stmt = $db->prepare("DELETE FROM player_strengths WHERE player_id = ?");
|
$stmt = $db->prepare("DELETE FROM player_strengths WHERE player_id = ?");
|
||||||
$stmt->execute([$id]);
|
$stmt->execute([$id]);
|
||||||
|
|
||||||
$stmt = $db->prepare("INSERT INTO player_strengths (player_id, strength) VALUES (?, ?)");
|
$stmt = $db->prepare("INSERT INTO player_strengths (player_id, strength) VALUES (?, ?)");
|
||||||
foreach ($data['strengths'] as $strength) {
|
foreach ($data['strengths'] as $strength) {
|
||||||
$stmt->execute([$id, $strength]);
|
$stmt->execute([$id, $strength]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mettre à jour les faiblesses si fourni
|
|
||||||
if (isset($data['weaknesses'])) {
|
if (isset($data['weaknesses'])) {
|
||||||
$stmt = $db->prepare("DELETE FROM player_weaknesses WHERE player_id = ?");
|
$stmt = $db->prepare("DELETE FROM player_weaknesses WHERE player_id = ?");
|
||||||
$stmt->execute([$id]);
|
$stmt->execute([$id]);
|
||||||
|
|
||||||
$stmt = $db->prepare("INSERT INTO player_weaknesses (player_id, weakness) VALUES (?, ?)");
|
$stmt = $db->prepare("INSERT INTO player_weaknesses (player_id, weakness) VALUES (?, ?)");
|
||||||
foreach ($data['weaknesses'] as $weakness) {
|
foreach ($data['weaknesses'] as $weakness) {
|
||||||
$stmt->execute([$id, $weakness]);
|
$stmt->execute([$id, $weakness]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->commit();
|
$db->commit();
|
||||||
jsonResponse(['success' => true, 'message' => 'Joueur mis à jour avec succès']);
|
jsonResponse(['success' => true, 'message' => 'Joueur mis à jour avec succès']);
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$db->rollBack();
|
$db->rollBack();
|
||||||
jsonResponse(['error' => 'Erreur lors de la mise à jour: ' . $e->getMessage()], 500);
|
jsonResponse(['error' => 'Erreur lors de la mise à jour: ' . $e->getMessage()], 500);
|
||||||
@@ -337,14 +270,11 @@ function updatePlayer($id) {
|
|||||||
|
|
||||||
function deletePlayer($id) {
|
function deletePlayer($id) {
|
||||||
$db = getDB();
|
$db = getDB();
|
||||||
|
|
||||||
$stmt = $db->prepare("DELETE FROM players WHERE id = ?");
|
$stmt = $db->prepare("DELETE FROM players WHERE id = ?");
|
||||||
$stmt->execute([$id]);
|
$stmt->execute([$id]);
|
||||||
|
|
||||||
if ($stmt->rowCount() === 0) {
|
if ($stmt->rowCount() === 0) {
|
||||||
jsonResponse(['error' => 'Joueur non trouvé'], 404);
|
jsonResponse(['error' => 'Joueur non trouvé'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonResponse(['success' => true, 'message' => 'Joueur supprimé avec succès']);
|
jsonResponse(['success' => true, 'message' => 'Joueur supprimé avec succès']);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user