What are the advantages of using a database for managing voting data in PHP?

Using a database for managing voting data in PHP allows for efficient storage, retrieval, and manipulation of large amounts of data. It provides a structured way to organize and access voting information, making it easier to analyze and generate reports. Additionally, databases offer built-in security features to protect sensitive voter data from unauthorized access.

// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "voting_data";

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

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