What are the advantages of using an adapter instead of extending the MySQLi class in PHP?

When extending the MySQLi class in PHP, you tightly couple your code to the specific implementation of the MySQLi class. This can make it difficult to switch to a different database system in the future. Using an adapter pattern allows you to create a layer of abstraction between your code and the database operations, making it easier to switch to a different database system without changing your code significantly.

// Adapter class to abstract database operations
class DatabaseAdapter {
    private $mysqli;

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

    public function query($query) {
        return $this->mysqli->query($query);
    }

    // Add more methods as needed
}

// Example usage of the DatabaseAdapter
$adapter = new DatabaseAdapter('localhost', 'username', 'password', 'database');
$result = $adapter->query('SELECT * FROM table_name');