How can PHP be integrated with MySQL to efficiently manage and display player stats on a website like a Torschützenliste?

To efficiently manage and display player stats on a website like a Torschützenliste, PHP can be integrated with MySQL by establishing a connection to the database, querying the relevant player stats data, and then displaying it on the website using HTML and PHP.

<?php
// Establish a connection to the MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Query the player stats data from the database
$sql = "SELECT player_name, goals_scored FROM player_stats ORDER BY goals_scored DESC";
$result = $conn->query($sql);

// Display the player stats on the website
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "Player: " . $row["player_name"]. " - Goals Scored: " . $row["goals_scored"]. "<br>";
    }
} else {
    echo "No player stats found";
}

$conn->close();
?>