What are some best practices for handling result sets in PHP when using a custom class for database operations?

When handling result sets in PHP using a custom class for database operations, it is important to properly encapsulate the data and provide methods for accessing and manipulating the results. One common approach is to create a custom class that represents a single row in the result set, and then have a separate class that represents the entire result set. This allows for better organization and abstraction of the data.

class Row {
    private $data;

    public function __construct($data) {
        $this->data = $data;
    }

    public function getValue($key) {
        return $this->data[$key];
    }

    // Add any other methods for manipulating the row data
}

class ResultSet {
    private $rows = [];

    public function addRow($data) {
        $this->rows[] = new Row($data);
    }

    public function getRows() {
        return $this->rows;
    }

    // Add any other methods for accessing/manipulating the result set
}