What are the potential pitfalls of using a custom MySQL class in PHP for database connections?

One potential pitfall of using a custom MySQL class in PHP for database connections is that it may not handle errors or exceptions properly, leading to potential security vulnerabilities or data loss. To solve this issue, it is important to implement proper error handling and exception catching in the custom MySQL class to ensure that any errors are logged and handled appropriately.

class CustomMySQL {
    private $connection;

    public function __construct($host, $username, $password, $database) {
        $this->connection = new mysqli($host, $username, $password, $database);

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

    public function query($sql) {
        $result = $this->connection->query($sql);

        if (!$result) {
            die("Query failed: " . $this->connection->error);
        }

        return $result;
    }

    public function close() {
        $this->connection->close();
    }
}