How can the error_reporting and ini_set functions be used to debug PHP code related to database connections?

To debug PHP code related to database connections, you can use the error_reporting function to display any errors or warnings related to database connections. Additionally, you can use the ini_set function to adjust the error reporting level to include database-related errors. This can help you identify and troubleshoot any issues with your database connections more effectively.

// Set error reporting to display all errors
error_reporting(E_ALL);

// Adjust error reporting level to include database-related errors
ini_set('display_errors', 1);

// Your database connection code here
$conn = new mysqli($servername, $username, $password, $dbname);

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