What are some potential pitfalls when connecting a MariaDB database to a webpage using PHP?

One potential pitfall when connecting a MariaDB database to a webpage using PHP is not properly handling errors or exceptions that may occur during the connection process. To solve this issue, it is important to implement error handling mechanisms to catch and display any potential errors that may arise.

// Connect to MariaDB database
$servername = "localhost";
$username = "username";
$password = "password";
$database = "dbname";

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

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