What is the purpose of the connection.php file in PHP development?

The purpose of the connection.php file in PHP development is to establish a connection to a database. By including this file in other PHP scripts, developers can easily connect to the database without having to rewrite the connection code in every script.

<?php
// connection.php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";

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

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