Are there any specific PHP functions or configurations that can streamline error reporting and handling in database operations?

When working with database operations in PHP, it is essential to have robust error reporting and handling mechanisms in place to efficiently debug and troubleshoot issues. One way to streamline error reporting is by setting the error reporting level to include warnings and errors related to database operations. Additionally, using try-catch blocks can help catch and handle exceptions that may occur during database queries.

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

// Database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Database query
    $stmt = $conn->prepare("SELECT * FROM table");
    $stmt->execute();

    // Fetch results
    $result = $stmt->fetchAll();
    
    // Handle results
    // ...
} catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}