better to wrap the result object in its own class, separate from the connection object wrapper: __destruct() can be used to automatically free the result set. this isn't a terribly new design pattern, either.
just be sure to destroy your result object before you make another query with the same DBI instance if you happen to change the flag to MYSQLI_USE_RESULT. actually, you'll find if you write the code with or without a wrapper class that it looks rather the same.
this code also allows you to track what kind of result set you've created by passing the flag around, although i don't think i'd ever need to use that myself.
class DBI
{
function __construct()
{
$this->dbconn = new mysqli(...);
}
function query($sql, $flag = MYSQLI_STORE_RESULT)
{
$result = $this->dbconn->query($sql, $flag);
return new RecordSet($result, $flag);
}
};
class RecordSet
{
function __construct($res, $flag = MYSQLI_STORE_RESULT)
{
$this->result = $res;
$this->flag = $flag;
}
function __destruct()
{
$this->result->free();
}
};