How can the PHP error log be utilized to troubleshoot HTTP 500 Internal Server Errors related to database connections?

When troubleshooting HTTP 500 Internal Server Errors related to database connections, the PHP error log can be utilized to identify any specific errors or issues with the database connection code. By checking the error log, you can pinpoint the exact error message or line of code causing the problem, allowing you to make necessary adjustments to fix the issue.

// Example code snippet to connect to a MySQL database and log any errors to the PHP error log
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

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

if ($conn->connect_error) {
    error_log("Database connection failed: " . $conn->connect_error);
}