How can error reporting be increased in PHP to troubleshoot database connection issues?

To increase error reporting in PHP to troubleshoot database connection issues, you can set the error reporting level to display all errors and warnings. This can help identify any issues with the database connection such as incorrect credentials or server configuration problems.

// Set error reporting level to display all errors and warnings
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Your database connection code here
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

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

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