Unlike the old MySQL functions, MySQLi methods don't return resources. They either return an object or some other string/integer/boolean/null type. The error message is crystal clear. The function get_resource_type()
expects a resource, as an argument, and you're giving it an object.
Be sure to read about Types in PHP for clarification on the differences between resource types and object types.
My guess here is that you expect $this->queryid
to be a MySQLi_Result
object, and that's what you're trying to check for. So rather than get_resource_type()
use the instanceof
operator instead, to check the object's type.
function free_result($queryid = -1) {
if($queryid != -1) {
$this->queryid = $queryid;
}
if($this->queryid instanceof MySQLi_Result)
return mysqli_free_result($this->queryid);
} else {
return false;
}
}
Alternatively, you can just Type Hint the function's prototype to only accept objects of type MySQLi_Result
to simplify your code and make it easier to test.
function free_result(MySQLi_Result $queryid = null) {
if($queryid) {
$this->queryid = $queryid;
}
if($this->queryid instanceof MySQLi_Result) {
return mysqli_free_result($this->queryid);
} else {
return false;
}
}
Also, please stop using the error silence operator @
. No good can ever come of that.
Make sure you're calling mysqli_free_result()
and not the old mysql_free_result()
function, also, as mentioned in the comments.