What are best practices for handling error messages in PHP scripts related to MySQL connections?

When handling error messages in PHP scripts related to MySQL connections, it is important to check for errors after each connection attempt and handle them appropriately. One common practice is to use the `mysqli_connect_error()` function to retrieve the error message and display it to the user or log it for debugging purposes.

// Attempt to establish a connection to the MySQL database
$connection = mysqli_connect($host, $username, $password, $database);

// Check for connection errors
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}

// Continue with your database operations here