How should connections between a database and phpMyAdmin be managed in PHP development?

When working with PHP development, connections between a database and phpMyAdmin should be managed securely to prevent unauthorized access to sensitive data. One way to achieve this is by storing database credentials in a separate configuration file outside of the web root directory. This helps to protect the credentials from being exposed in case of a security breach.

<?php
// Include the database configuration file
include 'config.php';

// Create a connection to the database
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";

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

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