What are the benefits of storing file paths and descriptions in a database instead of in session variables in a PHP script?

Storing file paths and descriptions in a database instead of in session variables allows for better organization, scalability, and easier access to the data throughout the application. By storing this information in a database, it can be easily queried, updated, and shared across multiple users or sessions.

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

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

// Query the database for file paths and descriptions
$sql = "SELECT file_path, description FROM files";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        echo "File Path: " . $row["file_path"]. " - Description: " . $row["description"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();