What is the purpose of XAMPP in relation to PHP and MySQL servers?

XAMPP is a free and open-source cross-platform web server solution stack package developed by Apache Friends, consisting mainly of the Apache HTTP Server, MariaDB database, and interpreters for scripts written in the PHP and Perl programming languages. It is designed to be a simple and lightweight solution for developers to create a local web server environment for testing and development purposes. XAMPP allows developers to easily set up and run PHP and MySQL servers on their local machines without the need for complex configurations.

// Sample PHP code using XAMPP to connect to a MySQL database

$servername = "localhost";
$username = "root";
$password = "";
$database = "my_database";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);

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

echo "Connected successfully";

// Close connection
$conn->close();