What are the potential pitfalls of using mysqli in a PHP class for creating a PDF file?

One potential pitfall of using mysqli in a PHP class for creating a PDF file is that it can lead to mixing database logic with presentation logic, which goes against the principles of separation of concerns. To solve this issue, it's recommended to separate the database operations into a separate class and then use the data retrieved from the database to generate the PDF file in a separate class.

// Separate class for handling database operations
class Database {
    private $conn;

    public function __construct() {
        $this->conn = new mysqli("localhost", "username", "password", "dbname");
        if ($this->conn->connect_error) {
            die("Connection failed: " . $this->conn->connect_error);
        }
    }

    public function getData() {
        // Implement your database query here
        $result = $this->conn->query("SELECT * FROM table");
        return $result->fetch_all(MYSQLI_ASSOC);
    }
}

// Separate class for generating PDF file
class PDFGenerator {
    public function generatePDF() {
        $database = new Database();
        $data = $database->getData();

        // Generate PDF file using $data
        // Add your PDF generation logic here
    }
}

// Usage
$pdfGenerator = new PDFGenerator();
$pdfGenerator->generatePDF();